我正在尝试将我的项目从java 8迁移到java 11。
<source>8</source>
<target>8</target>使用
<release>11</release> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>[11,12)</version>
</jdk>
</toolchains>
</configuration>
</plugin>之后,没有使用groovy编译的模块就没有问题。但是这个项目中很少有模块使用groovy。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.6.0-03</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>3.0.3-01</version>
</dependency>
</dependencies>
</plugin>我得到以下错误:
[INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files
[DEBUG] Compiling 15 source files to D:\Projects\dxcore-java11\fix-markets\fix-server-tests\target\classes
[DEBUG] Command line options:
[DEBUG] -cp D:\Projects\dxcore-java11\fix-markets\target\classes;C:\Users\turbanov\.m2\repository\org\codehaus\groovy\groovy\3.0.3\groovy-3.0.3.jar;<a_lot_of_jars_here>; -d D:\Projects\dxcore-java11\fix-markets\target\classes -s D:\Projects\dxcore-java11\fix-markets\target\generated-sources\annotations -g -encoding UTF8 --release 11 -nowarn D:\Projects\dxcore-java11\fix-markets\src\client\TestClient.groovy
[INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files
[DEBUG] Compiling 15 source files to D:\Projects\dxcore-java11\fix-markets\fix-server-tests\target\classes
[INFO] Compiling in a forked process using C:\Users\turbanov\.m2\repository\org\codehaus\groovy\groovy-eclipse-batch\3.0.3-01\groovy-eclipse-batch-3.0.3-01.jar
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Failure executing groovy-eclipse compiler:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project fix-server-tests: Compilation failure
Failure executing groovy-eclipse compiler:
option --release is supported only when run with JDK 9 or above
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:190)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure我的配置有什么问题?groovy-eclipse-compiler支持这样的配置吗?
奇怪的是,如果我将<release>替换回使用<source>11</source>/<target>8</target>,那么所有的构建都很好。
发布于 2021-03-12 17:13:21
我正在尝试将我的项目从java 8迁移到java 11。 我想使用新的语言特性和新的API。
这种迁移最简单的解决方案是使用Java 11进行Maven调用。在这种情况下不需要使用maven-toolchains-plugin。
至于groovy-eclipse-compiler报告的错误-- 发布新版本的插件以支持Java 11问题中的每一个示例都是使用具有以下两种显式配置的maven-compiler-plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>或者使用这样的隐式配置:
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>我建议遵循这些示例,完全放弃<release>配置。
另一个建议是使用maven-enforcer-plugin来实现强制使用用于Maven调用的Java的最低版本。
发布于 2021-03-17 21:12:01
如@emiles上文所述:
是的,经过一些研究之后,我发现groovy编译器并不是工具链感知的。我创建了这个github问题来跟踪这个功能的增加: github.com/groovy/groovy-eclipse/issues/1232
他于3月13日将修复程序放入编译器3.7.0中。我在AEM构建中遇到了同样的问题,使用maven工具链插件进行切换,在安装了JDK8和JDK11的安装上编译groovy。
升级到groovy编译器3.7.0和groovy批3.0.7-02为我解决了这个问题。
https://stackoverflow.com/questions/66603522
复制相似问题