【发布时间】:2019-07-06 22:48:37
【问题描述】:
我尝试使用 OpenJDK11 在 Jenkins 中构建工件。首先我运行mvn clean install -DskipTests 并构建成功。
但是当我运行mvn clean install 时,我收到了测试类的以下错误。
<CLASS_NAME> has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
<CLASS_NAME> has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
pom.xml
<properties>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
<compilerId>groovy-eclipse-compiler</compilerId>
<compilerArguments>
<indy/>
<configScript>config.groovy</configScript>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.0.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.5.5-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<includes>
<include>**/*Spec.*</include>
</includes>
</configuration>
</plugin>
</plugins>
请帮助我在 Jenkins 中解决此问题
注意:我在本地也遇到了类似的问题。我在 ~/.mavenrc 文件中更改了 JAVA_HOME,问题得到了解决
【问题讨论】:
-
jenkins server 中可能有多个 java 版本吗?你的詹金斯项目如何配置?使用詹金斯管道?
-
我猜 maven-compiler-plugin 采用了 pom.xml 中提到的 Java 版本,但没有采用 maven-surefire-plugin .. 有没有办法在 maven-surefire-plugin 中强制执行 java 版本?
-
使用 toolchains.xml 的解决方案是您可能正在寻找的 - maven.apache.org/surefire/maven-surefire-plugin/java9.html
-
在 ~/.mavenrc 文件中更改 JAVA_HOME 后问题得到解决。
标签: java maven jenkins maven-surefire-plugin java-11