微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

马文无法使用 groovy-eclipse 编译器编译模块

如何解决马文无法使用 groovy-eclipse 编译器编译模块

我正在尝试将我的项目从 java 8 迁移到 java 11。 我在 root pom.xml 中做了什么:

  1. 已替换
<source>8</source>
<target>8</target>

<release>11</release>
  1. 已配置的 maven-toolchain-plugin
            <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>,所有构建都很好。

解决方法

我正在尝试将我的项目从 java 8 迁移到 java 11。

我想使用新的语言功能和新的 API。

此迁移最简单的解决方案是使用 Java 11 进行 Maven 调用。在这种情况下不需要使用 maven-toolchains-plugin

至于 groovy-eclipse-compiler 报告的错误 - Release new version of Groovy Eclipse Maven plugin to support 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-pluginenforce the minimum version of Java used for Maven invocation

,

正如@emiles 上面评论的那样:

是的,经过一些研究,我现在发现 groovy-eclipse-compiler 不支持工具链。我创建了这个 github 问题来跟踪此功能的添加:github.com/groovy/groovy-eclipse/issues/1232

他于 3 月 13 日将修复程序放入 groovy-eclipse-compiler 3.7.0。我在 AEM 构建上遇到了同样的问题,在安装了 JDK8 和 JDK11 的 AEM Cloud Manager 安装上编译 groovy,使用 maven-toolchains-plugin 进行切换。

升级到 groovy-eclipse-compiler 3.7.0 和 groovy-eclipse-batch 3.0.7-02 为我解决了这个问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?