4

we have a Jenkins job which is/was configured to use JDK7. Upon inspecting the logs, i noticed following ERRORs:

ERROR: Invalid project setup: jenkins/security/MasterToSlaveCallable : Unsupported major.minor version 52.0
ERROR: [JENKINS-18403][JENKINS-28294] JDK 'JDK 1.7.0_45' not supported to run Maven projects.
ERROR: Maven projects have to be launched with a Java version greater or equal to the minimum version required by the master.
ERROR: Use the Maven JDK Toolchains (plugin) to build your maven project with an older JDK.
ERROR: Retrying with slave Java and setting compile/test properties to point to /usr/java/jdk1.7.0_45/.

After some googling it seems that there is some interaction between the Job and Jenkins itself. Since Jenkins is started with JDK8 and the Job with JDK7 it seems to produce this ERROR. The build is OK, because Jenkins then proceeds to build with JDK8. But we actually want this built with 1.7.

So the question is: If we start Jenkins with JDK8, how can i get the Jobs to compile with JDK7 without this error?

JSamir
  • 1,057
  • 1
  • 10
  • 20
  • 3
    Don't use MavenJob Type...simply using pipeline jobs etc. there you can decide which JDK version you use ... – khmarbaise May 30 '17 at 16:12
  • The interaction is based on that Jenkins will try to be informed about finishing single modules and if there are artifacts being created and some other stuff. This is handled by a EventSpy implementation in Jenkins. That can cause issues like this. – khmarbaise May 30 '17 at 16:22
  • Is there something about the 1.7 tool chain or just need 1.7 bytecode? – bichito Jun 26 '17 at 11:54
  • @khmarbaise if you post your comment as an answer I would accept it since that helped me solve the problem by using a pipeline job. – JSamir Jun 27 '17 at 12:54

4 Answers4

3

this is apparently a technical limitation of Jenkins plugin Maven Integration.

Because java serialized classes are exchanged between Jenkins master and Maven Jobs it is required that the JVM used to launch Maven is superior or equal to the version of Java for which Jenkins Master is built for.

I suspect that you have a Jenkins version too recent, requiring a JDK version >= 8.
As the required version was 7, you could either use java 7 or 8 - or even 9. So your build succeeded with Java7, even if your Jenkins was started with Java8.

You can either downgrade your Jenkins installation, or move all your builds to Java8.

Cheers

Kineolyan
  • 723
  • 8
  • 24
2

As you might probably know Jenkins >= 2.54 requires Java >= 8 thus Maven jobs must be launched with Java >= 8

Besides that the Error message is guiding you with:

Use the Maven JDK Toolchains (plugin) to build your maven project...

Using that plugin would probably help you to run your jenkins job using Java 8 and also compile your project files using Java 7.

I resolved my problem this way some years ago.

You can see more details on this Answer.

Kayvan Tehrani
  • 3,070
  • 2
  • 32
  • 46
  • 1
    I would migrate away from "Maven project" to "Free-style project". But it was not possible in my case (we had way too many jobs). And Toolchains were the only reliable working solution I found. Thank you! – bugs_ Dec 15 '22 at 08:27
2

For using Java 1.7 on Jenkins >= 2.54 you need to transform the Maven project in a Free-style project. In the Free-style project you can specify the JDK version. This is because starting from version 2.54, Jenkins was upgraded to use Java 8.

From Jenkins release notes:

Using the Maven project type with Java 7

Users with jobs configured with the "Maven project" type may not be able to use Java 7 for their Maven jobs. The correct behavior is not guaranteed so proceed at your own risk. The Maven Project uses Jenkins Remoting to establish "interceptors" within the Maven executable. Because of this, Maven uses Remoting and other Jenkins core classes, and this behavior may break an update

You can also see here how to create a Free-style project

pringi
  • 3,987
  • 5
  • 35
  • 45
1

The interaction is based on that Jenkins will try to be informed about finishing single modules and if there are artifacts being created and some other stuff. This is handled by a EventSpy implementation in Jenkins. That can cause issues like this.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • This is the relevant part of my jenkinsfile, where i set JAVA_HOME to the version needed for the current stage: `env.JAVA_HOME="${tool 'JDK17'}" env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"` – JSamir Jun 27 '17 at 16:36