Макросы Scala 2.12.8 с Maven - PullRequest
1 голос
/ 13 мая 2019

Я пытаюсь использовать Scala Macros с Maven!

Я нашел старый ответ на Stackoverflow ЗДЕСЬ , но, похоже, он не работает в моем случае. Я получил ошибку во время компиляции, даже если в моем коде нет макросов!

Поиск в Google Я не нашел много документации об этой функции, используемой с Maven. К сожалению, мы работаем над устаревшим Java-проектом и по этой причине не можем перейти на SBT.

Я получил следующую ошибку:

Error:scalac: Error: scala.tools.nsc.typechecker.Namers$Namer.enterDefaultGetters(Lscala/reflect/internal/Symbols$Symbol;Lscala/reflect/internal/Trees$DefDef;Lscala/collection/immutable/List;Lscala/collection/immutable/List;)V
java.lang.NoSuchMethodError: scala.tools.nsc.typechecker.Namers$Namer.enterDefaultGetters(Lscala/reflect/internal/Symbols$Symbol;Lscala/reflect/internal/Trees$DefDef;Lscala/collection/immutable/List;Lscala/collection/immutable/List;)V

    at org.scalamacros.paradise.typechecker.Namers$Namer.$anonfun$finishSymbolNotExpandee$1(Namers.scala:282)

    at org.scalamacros.paradise.typechecker.Namers$Namer.savingLock$1(Namers.scala:215)

    at org.scalamacros.paradise.typechecker.Namers$Namer.finishSymbolNotExpandee(Namers.scala:219)

    at org.scalamacros.paradise.typechecker.Namers$Namer.finishSymbolNotExpandee$(Namers.scala:211)

    at org.scalamacros.paradise.typechecker.Namers$$anon$1.finishSymbolNotExpandee(Namers.scala:13)

    at org.scalamacros.paradise.typechecker.Namers$Namer.finishSymbol(Namers.scala:183)

    at org.scalamacros.paradise.typechecker.Namers$Namer.finishSymbol$(Namers.scala:166)

    at org.scalamacros.paradise.typechecker.Namers$$anon$1.finishSymbol(Namers.scala:13)

    at org.scalamacros.paradise.typechecker.Namers$Namer.dispatch$1(Namers.scala:35)

    at org.scalamacros.paradise.typechecker.Namers$Namer.enterSym(Namers.scala:41)

    at org.scalamacros.paradise.typechecker.Namers$Namer.enterSym$(Namers.scala:23)

    at org.scalamacros.paradise.typechecker.Namers$$anon$1.enterSym(Namers.scala:13)

    at org.scalamacros.paradise.typechecker.AnalyzerPlugins$MacroPlugin$.pluginsEnterSym(AnalyzerPlugins.scala:36)

    at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$15.custom(AnalyzerPlugins.scala:461)

    at scala.tools.nsc.typechecker.AnalyzerPlugins.$anonfun$invoke$3(AnalyzerPlugins.scala:403)

    at scala.tools.nsc.typechecker.AnalyzerPlugins.invoke(AnalyzerPlugins.scala:403)

    at scala.tools.nsc.typechecker.AnalyzerPlugins.pluginsEnterSym(AnalyzerPlugins.scala:455)

    at scala.tools.nsc.typechecker.AnalyzerPlugins.pluginsEnterSym$(AnalyzerPlugins.scala:453)

    at scala.tools.nsc.Global$$anon$1.pluginsEnterSym(Global.scala:458)

    at scala.tools.nsc.typechecker.Namers$Namer.enterSym(Namers.scala:261)

    at scala.tools.nsc.typechecker.Namers$Namer.enterSyntheticSym(Namers.scala:801)

    at scala.tools.nsc.typechecker.Namers$Namer.$anonfun$addCopyMethod$1(Namers.scala:1749)

    at scala.tools.nsc.typechecker.Namers$Namer.addCopyMethod(Namers.scala:1749)

    at scala.tools.nsc.typechecker.Namers$Namer.$anonfun$templateSig$6(Namers.scala:1168)

    at scala.tools.nsc.typechecker.Namers$Namer.templateSig(Namers.scala:1162)

    at scala.tools.nsc.typechecker.Namers$Namer.classSig(Namers.scala:1187)

    at scala.tools.nsc.typechecker.Namers$Namer.memberSig(Namers.scala:1798)

    at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:1761)

    at scala.tools.nsc.typechecker.Namers$Namer$MonoTypeCompleter.completeImpl(Namers.scala:840)

    at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter.complete(Namers.scala:1958)

    at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter.complete$(Namers.scala:1956)

    at scala.tools.nsc.typechecker.Namers$TypeCompleterBase.complete(Namers.scala:1951)

    at scala.tools.nsc.typechecker.Namers$PolyTypeCompleter.completeImpl(Namers.scala:1991)

    at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter.complete(Namers.scala:1958)

    at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter.complete$(Namers.scala:1956)

    at scala.tools.nsc.typechecker.Namers$PolyTypeCompleter.complete(Namers.scala:1970)

    at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1530)

    at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1678)

    at scala.tools.nsc.typechecker.Typers$Typer.checkNotLocked$1(Typers.scala:306)

    at scala.tools.nsc.typechecker.Typers$Typer.checkNonCyclic(Typers.scala:310)

    at scala.tools.nsc.typechecker.Typers$Typer.checkNonCyclic(Typers.scala:328)

    at scala.tools.nsc.typechecker.Typers$Typer.checkNonCyclic(Typers.scala:338)

    at scala.tools.nsc.typechecker.Typers$Typer.typedValDefImpl(Typers.scala:2039)

    at scala.tools.nsc.typechecker.Typers$Typer.typedValDef(Typers.scala:2024)

    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5494)

    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5546)

    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5584)

    at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5616)

    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5557)

    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5562)

    at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5647)

    at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:3086)

    at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$10(Typers.scala:3231)

    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3231)

    at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1987)

    at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:1811)

    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5496)

    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5546)

    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5584)

    at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5616)

    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5557)

    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5562)

    at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5647)

    at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:3086)

    at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$10(Typers.scala:3231)

    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3231)

    at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1987)

    at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:1811)

    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5496)

    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5546)

    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5584)

    at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5616)

    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5557)

    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5562)

    at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5647)

    at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:3086)

    at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$10(Typers.scala:3231)

    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3231)

    at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5207)

    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5499)

    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5546)

    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5584)

    at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5616)

    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5557)

    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5562)

    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5643)

    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:104)

    at scala.tools.nsc.Global$GlobalPhase.$anonfun$applyPhase$1(Global.scala:436)

    at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:429)

    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.$anonfun$run$1(Analyzer.scala:94)

    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.$anonfun$run$1$adapted(Analyzer.scala:93)

    at scala.collection.Iterator.foreach(Iterator.scala:929)

    at scala.collection.Iterator.foreach$(Iterator.scala:929)

    at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)

    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:93)

    at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1452)

    at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1436)

    at scala.tools.nsc.Global$Run.compileSources(Global.scala:1429)

    at scala.tools.nsc.Global$Run.compile(Global.scala:1545)

    at xsbt.CachedCompiler0.run(CompilerInterface.scala:130)

    at xsbt.CachedCompiler0.run(CompilerInterface.scala:105)

    at xsbt.CompilerInterface.run(CompilerInterface.scala:31)

    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:237)

    at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:111)

    at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:90)

    at org.jetbrains.jps.incremental.scala.local.IdeaIncrementalCompiler.compile(IdeaIncrementalCompiler.scala:40)

    at org.jetbrains.jps.incremental.scala.local.LocalServer.compile(LocalServer.scala:35)

    at org.jetbrains.jps.incremental.scala.remote.Main$.make(Main.scala:83)

    at org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:26)

    at org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)

    at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at com.martiansoftware.nailgun.NGSession.run(NGSession.java:319)

ENV:

  • Scala 2.12.8
  • JDK 1.8.0_152

РОМ:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <properties>
        <scala.version>2.12.8</scala.version>
    </properties>
    <repositories>
        <repository>
            <id>oss.sonatype.org</id>
            <name>sonatype sapshots</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-compiler</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-reflect</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest-maven-plugin</artifactId>
            <version>2.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_2.12</artifactId>
            <version>3.0.7</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.4.6</version>
                <configuration>
                    <scalaVersion>${scala.version}</scalaVersion>
                    <args>
                        <arg>-target:jvm-1.8</arg>
                        <arg>-Xlint</arg>
                        <arg>-deprecation</arg>
                        <arg>-unchecked</arg>
                        <arg>-feature</arg>
                        <arg>-language:postfixOps</arg>
                        <arg>-language:implicitConversions</arg>
                        <arg>-language:higherKinds</arg>
                        <arg>-Xfatal-warnings</arg>
                        <arg>-Ywarn-unused-import</arg>
                        <arg>-Ywarn-inaccessible</arg>
                        <arg>-Ywarn-dead-code</arg>
                        <arg>-Ypartial-unification</arg>
                    </args>
                    <compilerPlugins>
                        <compilerPlugin>
                            <groupId>org.scala-lang.plugins</groupId>
                            <artifactId>macro-paradise_${scala.version}</artifactId>
                            <version>2.1.1</version>
                        </compilerPlugin>
                    </compilerPlugins>
                </configuration>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Спасибо за поддержку.

1 Ответ

0 голосов
/ 26 июня 2019

Попробуйте

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>scala_macros_maven_demo</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <scala.version>2.12.8</scala.version>
<!--        <scala.version>2.13.0</scala.version>-->
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
    </dependencies>

    <modules>
        <module>core</module>
        <module>macros</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>4.1.0</version>

                <configuration>

                   <!-- for Scala 2.12.8 -->
                    <compilerPlugins>
<!--                        <compilerPlugin>-->
<!--                            <groupId>org.scalamacros</groupId>-->
<!--                            <artifactId>paradise_${scala.version}</artifactId>-->
<!--                            <version>2.1.1</version>-->
<!--                        </compilerPlugin>-->

                        <compilerPlugin>
                            <groupId>org.scalameta</groupId>
                            <artifactId>paradise_${scala.version}</artifactId>
                            <version>3.0.0-M11</version>
                        </compilerPlugin>
                    </compilerPlugins>

                   <!-- for Scala 2.13.0  -->
<!--                    <args>-->
<!--                        <arg>-Ymacro-annotations</arg>-->
<!--                    </args>-->

                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

макросы / pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>scala_macros_maven_demo</artifactId>
        <groupId>com.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>macros</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-reflect</artifactId>
            <version>${scala.version}</version>
        </dependency>
    </dependencies>
</project>

ядро ​​/ pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>scala_macros_maven_demo</artifactId>
        <groupId>com.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>core</artifactId>

    <dependencies>
        <dependency>
            <artifactId>macros</artifactId>
            <groupId>com.example</groupId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>

                <configuration>
                    <launchers>
                        <launcher>
                            <id>launcher1</id>
                            <mainClass>com.example.App</mainClass>
                        </launcher>
                    </launchers>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
...