Maven uses the wrong version of Java when it runs Jenkins

I have some projects compiled and deployed with Maven and Jenkins, and they still worked fine, that I changed the java version from 6 to 7.

To do this, I ran the sudo update-alternatives --config javac command and changed the JAVA_HOME and PATH values ​​in the / etc / profile file. I also changed the pom file, so it uses jdk 1.7:

<properties> ... <jdk.version>1.7</jdk.version> </properties> <plugin> <artifactId>maven-compiler-plugin</artifactId> ... <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> </configuration> </plugin> 

When I execute them on the console, they compile in perfect order and the displayed version is correct:

 javac -version javac 1.7.0_55 mvn install -debug Apache Maven 2.2.1 (rdebian-8) Java version: 1.7.0_55 Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre 

However, when I do the same in jenkins work, Maven uses version 1.6 instead of 1.7:

 javac -version javac 1.7.0_55 mvn install -debug Apache Maven 2.2.1 (rdebian-8) Java version: 1.6.0_31 Java home: /usr/lib/jvm/java-6-openjdk-amd64/jre 

I also changed the maven configuration file, which I use to indicate the new version, and in the Jenkins admin panel, I changed the version of the JDK. However, Maven still uses 1.6 jdk.

Do you know how I can change it?

+5
java linux maven jenkins
source share
2 answers

I found a solution here . You must define the JAVA_HOME variable also in the Jenkins global configuration. As Sudarsan explained, the steps are:

  • Go to Jenkins Management - System Configuration

  • Add JAVA_HOME and its path in global properties - environment variables

+4
source share

We had a similar problem when changing Jenkins jobs from JDK 1.6 to JDK 1.8. I deleted the JDK1.6 entry from "Managing the Jenkins / Configure System", leaving only JDK1.8. I expected jobs to start using JDK1.8, but they did not. I checked the assignments and they did not have any JDK assignments. Restarting Jenkins did not help either.

In the end, I noticed that just by doing the job again, he started using the correct JDK1.8.

(Jenkins version 1.602)

+3
source share

All Articles