When I try to run my Jenkins Maven job I get the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project myProject: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
This indicates that Maven uses Java 1.8 but it is supposed to use Java 1.7.
I ran Maven in debug mode and it displayed the right versions:
...
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven305
Java version: 1.7.0_71, vendor: Oracle Corporation
Java home: /var/lib/jenkins/tools/hudson.model.JDK/JDK_7u71/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.8.0-44-generic", arch: "amd64", family: "unix"
...
The Jenkins server runs with Java 1.8
...
$ java -version
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
...
$ javac -version
javac 1.8.0_74
...
I tried running the job with an empty Maven repo and telling Maven exactly which version to use but with no success.
I call Maven like this:
mvn clean install -X -DskipTests -Dmaven.repo.local=../testrepo -Djava.version=1.7
Am I doing something wrong?
Proper solution is to add needed JDK to Jenkins global configuration and then to specifically choose needed JDK version/installation under the project build configuration.
Start by copying needed JDKs to your build machine. Then open Jenkins configuration and scroll to "JDK" section [Jenkins -> Manage Jenkins -> Configure System]. Add desired JDKs to Jenkins. Following picture is example of Jenkins configured with two different JDKs.
Now under project configuration [YourProject -> Configure], a new option will be available. You can select desired JDK to build project with as in the picture:
"(Default)" JVM in picture refers to the JDK under which Jenkins run. Easy fix would be to change this JDK to the version needed for your project (either by changing Jenkins start script or using JAVA_HOME). This will work. However once you have a need to build two or more conflicting projects, you are gonna need to configure multiple JDKs anyway.
By using similar steps you can add multiple maven installations to your Jenkins server.
In Jenkins 2.7.3 (and later on maybe) the menu navigation is slightly different:
1) Manage Jenkins
2) Global Tool Configuration
3) JDK section
4) press "JDK installations" button
5) JDK options and paths are there
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With