在Jenkins中运行mvn测试时,maven-surefire-plugin出现Java版本问题

时间:2019-02-13 07:12:25

标签: java maven jenkins maven-surefire-plugin java-11

我尝试使用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>

请帮助我解决詹金斯问题

注意:我在本地也遇到过类似的问题。我在〜/ .mavenrc 文件中更改了JAVA_HOME,问题已解决

1 个答案:

答案 0 :(得分:1)

这只是版本不匹配。您已经使用Java 8在本地编译了代码,并且您的Jenkins具有JAVA11。将本地代码升级到与Java 11兼容。 这是您细读的链接。

Class has been compiled by a more recent version of the Java Environment