Using SonarQube 5.4, Maven 3.3.9, Jenkins 2.19.1 on systems with both Java 1.7 and 1.8

Hello folks! My team spent hours and hours beating our head against a Sonar deployment problem on Ubuntu Trusty (14.04 LTS). I thought I might share our findings so that you won’t have to!

As you probably know, Trusty only makes Java Development Kit 1.7 available on the stock installation. The current stable version of the Java is 1.8. The way we install this is to use the OpenJDK PPA, generously uploaded by our dear friend Matthias Klose.

To make things even more exciting, a modern Maven is not available on this platform. And so we use the stock Maven 3.3.9 tarball distribution. This tarball distribution does not integrate well with Debian, and so, when we tell the system using sudo update-java-alternatives -s /usr/lib/jvm/java-1.8.0-openjdk-amd64 that we wish to use Java 1.8 as our default system JDK, it does not get the message.

The only way to reliably let Maven know which java you wish to use is to set the JAVA_HOME environment variable. In order to do this within the Jenkins environment, one must select the JDK one wishes to use:

openjdk8-ubuntu1404-as-jdk

To make things worse, this option is not, as one might expect, available for editing in a stock Jenkins 2.x installation. In Jenkins 1.x, one would be able to specify which java one wished to use just by specifying “openjdk8” in a field. With Jenkins 2.x, the field does not exist unless a configuration option in an unrelated form is set.

So! One should first select Manage Jenkins -> Global Tool Configuration:

Jenkins2-Global_Tool_Configuration

Once this form is open, look for the “JDK installations…” button:

Jenkins2-JDK_installations

Click it very thoroughly just once.

You’ll be presented with a form into which you may enter details about the various JDKs your build executors may have access to. You’ll refer to them in your job configuration by the value of their “Name” field, and when executing the build, Jenkins will set JAVA_HOME to the value of the (you guessed it) JAVA_HOME field:

Jenkins2-JDK_installations-expanded

Once these entries are made, they can be selected in two place.

1) on the ZMQ Event Publisher:

jdk-select-project

2) in the post-build actions under SonarQube analysis with Maven (advanced)

postbuild-sonarqube-select-jdk

And that’s how it’s done!

Here’s the details from my colleague, Thanh:

https://lists.fd.io/pipermail/honeycomb-dev/2016-October/000387.html

This entry was posted in debian, Free Software, java, linux, Linux Foundation, open source, openstack, Software, ubuntu, virtualization, work. Bookmark the permalink.

Leave a Reply