2
votes

I am running Jenkins ver. 1.532. I have created a maven job and tried to configure it to run java 5 using the jenkins JDK auto installer configured to download/install jdk5 from oracle. But when I run the build I get:

ERROR: [JENKINS-18403] JDK 5 not supported to run Maven; retrying with slave Java and setting compile/test properties to point to /var/jenkins/tools/hudson.model.JDK/jdk5
maven31-agent.jar already up to date
maven31-interceptor.jar already up to date
maven3-interceptor-commons.jar already up to date
[my-project] $ /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -cp /var/jenkins/maven31-agent.jar:/var/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven/boot/plexus-classworlds-2.4.2.jar:/var/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven/conf/logging jenkins.maven3.agent.Maven31Main 

It seems that it falls back to building with jdk7 (the default). I have then tried to add the following to the Builds/Goals and options section:

mvn clean install -Dmaven.compiler.executable=/var/lib/jenkins/tools/hudson.model.JDK/jdk5/bin/javac

But it does not have any effect. Should it not be possible to force a JDK version using -Dmaven.compiler.executable option?

EDIT: I have now switched to the jenkins freestyle project type and use the maven-enforcer-plugin to fail the build if a jdk != 1.5 is used when building the project. See last paragraph here:

https://blogs.oracle.com/darcy/entry/how_to_cross_compile_for

and Note here:

http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

2
Try using maven 2.2.1Peter Schuetze
can you explain why you cannot use jdk7 but with source+output set to java 5? wouldn't that be the easiest option?eis
Do you mean maven.apache.org/plugins/maven-compiler-plugin/examples/… ?. From the note I understand that you can still run into runtime errors with this approach. So it seems that the only way to be 100% sure is by building with a jdk version no higher than what you want to be compatible with.u123

2 Answers

2
votes

According to http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#executable , -Dmaven.compiler.executable will override compiler executable only for Maven compiler plugin, and not for the whole Jenkins job. If you need only to compile your sources using JAVA5 - setting this property should be enough to enforce Maven compiler to use JAVA5. Even in case when Jenkins job will use JDK 1.6 or higher for running the Maven launcher.

And, of course, you need to set JDK 1.6 or higher in Jenkins job settings. Since Jenkins cannot run Maven using JAVA5, you should not use it.

2
votes

I had a similar case which my help you.

My maven is running with JDK 1.7 but I wanna build a project with JDK 8.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

if I would just run mvn clean install I would get an error like:

Fatal error compiling: invalid target release: 1.8

When I set the JAVA_HOME to the JDK 8 it would work like a charm, but I don't want to do that.

The maven compiler has the option, like you mentioned executeable however this does not work in my case, it would still fail with the same error message.

I came up with the following command

mvn clean install -Dmaven.compiler.executable=/usr/lib/jvm/jdk1.8.0/bin/javac -Dmaven.compiler.fork=true

As additional information I appended the output of mvn -v

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: /opt/apache-maven-3.x
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /usr/lib/jvm/jdk1.7.0_45/jre
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "3.11.0-20-generic", arch: "amd64", family: "unix"