简体   繁体   English

在 Jenkins 中运行 mvn test 时 maven-surefire-plugin 的 Java 版本问题

[英]Java version issue with maven-surefire-plugin while running mvn test in Jenkins

I tried building artifact in Jenkins with OpenJDK11.我尝试使用 OpenJDK11 在 Jenkins 中构建工件。 First I ran mvn clean install -DskipTests & build was successful.首先我运行mvn clean install -DskipTests & build 成功。

But when I ran mvn clean install , I got following error for test classes.但是当我运行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 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>

Please help me in fixing this issue in Jenkins请帮助我在 Jenkins 中解决这个问题

Note : I faced similar issue in my local also.注意:我在本地也遇到了类似的问题。 I changed JAVA_HOME in ~/.mavenrc file & the issue got resolved我在~/.mavenrc文件中更改了 JAVA_HOME & 问题得到解决

This is just a version mismatch.这只是版本不匹配。 You have compiled your code in local using Java 8 and your Jenkins has JAVA 11. Upgrade your local code to Java 11 compatible.您已经使用 Java 8 在本地编译了代码,并且您的 Jenkins 有 JAVA 11。将您的本地代码升级到 Java 11 兼容。 This is the link for your perusal.这是供您阅读的链接。

Class has been compiled by a more recent version of the Java Environment 类已由更新版本的 Java 环境编译

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行 maven-surefire-plugin:test 时出现 lombok 编译错误 - lombok compilation errors when running maven-surefire-plugin:test JUnit 和 Spock 测试与 maven-surefire-plugin - JUnit and Spock test with maven-surefire-plugin 如何使用在docker中运行的mysql运行maven测试(使用maven-surefire-plugin) - How to run maven test with mysql running in docker (using maven-surefire-plugin) 从命令行运行 Maven 时“无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M1:test (default-test)” - " Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M1:test (default-test)" while running Maven from command line 带有Maven-surefire-plugin的UnsatisfiedLinkError - UnsatisfiedLinkError with maven-surefire-plugin maven-surefire-plugin包含单一测试不起作用 - maven-surefire-plugin inclusion of Single test is not working org.apache.maven.plugins:maven-surefire-plugin 的“build.plugins.plugin.version”丢失 - 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing 问题是使用测试 maven,显示此错误 Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) - Issue is using test maven, this error is displayed Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) maven-surefire-plugin包含/排除优先级 - maven-surefire-plugin include/exclude precedence 适用于Java 9模块的带有junit-platform-surefire-provider的Maven-surefire-plugin - Maven-surefire-plugin with junit-platform-surefire-provider for Java 9 module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM