4

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

IamVickyAV
  • 1,495
  • 1
  • 17
  • 15
  • May there are multiple java versions in jenkins server ? How does your jenkins project config ? Use jenkins pipeline? – tianzhipeng Feb 13 '19 at 07:29
  • I guess maven-compiler-plugin took Java version mentioned in pom.xml but not the maven-surefire-plugin.. Is there way to enforce java version in maven-surefire-plugin ? – IamVickyAV Feb 13 '19 at 08:49
  • 1
    Solution using ***toolchains.xml*** is what you might be looking for - https://maven.apache.org/surefire/maven-surefire-plugin/java9.html – Naman Feb 13 '19 at 09:24
  • After I changing JAVA_HOME in ~/.mavenrc file & the issue got resolved. – IamVickyAV Jul 02 '19 at 06:10

1 Answers1

1

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

Atul KS
  • 908
  • 11
  • 21
  • Thanks for your response. Your finding is correct. After I changed JAVA_HOME in ~/.mavenrc file & the issue got resolved for me. – IamVickyAV Jan 29 '20 at 09:22