Maven Builds Fails After Upgrade

Hello, we have upgraded Jenkins to the latest version, but instead of changing default java version from 8 to 11, we set path to java 11 for Jenkins from systemd files, Jenkins starts normally and all looks fine but when we run jobs with maven builds they are failing with following message:

[workspace] $ java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.13.jar:/usr/share/maven/boot/plexus-classworlds-2.x.jar:/usr/share/maven/conf/logging jenkins.maven3.agent.Maven35Main /usr/share/maven /var/cache/jenkins/war/WEB-INF/lib/remoting-3044.vb_940a_a_e4f72e.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.13.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.13.jar 37901
Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher 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
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:425)
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
	at jenkins.maven3.agent.Maven35Main.main(Maven35Main.java:135)
	at jenkins.maven3.agent.Maven35Main.main(Maven35Main.java:65)

If I set default Java version to 11 , all gets fixed. How we can resolve it by keeping default Java version as 8? I assume there is something needs JAVA_HOME to 11 .

As far as I know, you can’t run use Java 8 to compile a Maven job type when the Jenkins controller requires Java 11. The Maven job type is tied to the version of Java running on the controller. That is one of the reasons that the Maven job type has been advised against for many years. You can read more about it in the “Risks” section of the Maven job documentation.

You can convert the Maven job types to be Pipeline jobs and then can use the JDK tool of your choice to run the Pipeline job.

You can convert the Maven job types to be freestyle jobs and then can use the JDK tool of your choice to run the Pipeline job.

You may also be able to modify the pom file definitions of the Maven jobs so that even though they compile with Java 11, they generate Java 8 byte code. If your strict requirement is that you must compile with Java 8, then as far as I know, you’ll need to use a different type of Jenkins job.

yeah, that is true, thank you for replying. Following blog also recommends some solutions.

1 Like

Is anyone aware of a groovy script or other tool which can read an existing maven job type and replicate (ie: create new equivalent) as a Freestyle or Pipeline job base type ?

Similar question asked years ago:
How to properly switch from Maven-style jobs to Freestyle jobs?.

Automated conversion tool would help all those Java 8 users w/maven job type stuck in that quandry.

Maybe someone has something leftover form the Java 6 to Java 8 minima?

I think its one of those problems that sounds like it’ll be better to automate, but in reality, unless you have a metric ton of them, its probably not worth the effort, and will allow you to take the opportunity to clean things up and learn the new processes.

With the pipeline syntax generator (Sidebar on any pipeline job), you should be able to re-create most steps from freestyle/maven jobs. And the sample maven pipeline (assuming its still there) will get you started with having a tool setup, and windows and linux conditionals. (Declarative Pipeline for Maven Projects if the built in one doesn’t exist anymore)

That being said, there has been a number of attempts to write converters, but due to the freeform nature of jenkins, it tends to work for one person, and not end up being super reusable.