IamVickyAV
IamVickyAV

Reputation: 1555

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

I tried building artifact in Jenkins with OpenJDK11. First I ran mvn clean install -DskipTests & build was successful.

But when I ran mvn clean install, I got following error for test classes.

<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>

Please help me in fixing this issue in Jenkins

Note: I faced similar issue in my local also. I changed JAVA_HOME in ~/.mavenrc file & the issue got resolved

Upvotes: 4

Views: 4877

Answers (1)

Atul KS
Atul KS

Reputation: 990

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. This is the link for your perusal.

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

Upvotes: 1

Related Questions