user5494969
user5494969

Reputation: 191

Trying to use SonarQube on Jenkins to analyze project, but Jenkins using JDK 1.7 and I am getting an unsupported major.minor version error

I'm trying to analyze a git project using SonarQube and running that through Jenkins, however the Console Output gives me an error when I try to build.

java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/
EnvironmentInformation : Unsupported major.minor version 52.0

Screenshot -> https://i.sstatic.net/BzatZ.png

Which I have learned means I'm using a higher JDK at compile time than I am at runtime. When I ssh into the machine that is hosting Jenkins and the SonarQube server and run a

java -version

it outputs :

openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Which is what it should be-- SonarQube 5.6 needs Java 1.8 I believe?

Screenshot -> https://i.sstatic.net/GVpg6.jpg

But, I edit the Jenkins build to execute shell command at the beginning and had it run

java -version

and it outputted java version "1.7.0_79"

Screenshot -> i.imgur.com/ghGWpZx.png (near the bottom)

Can someone tell me what I'm doing wrong? How can I force Jenkins to use JDK 1.8? In my settings everything seems as if it is configured correctly

Screenshot -> i.imgur.com/3IXXEzg.png

[sorry, had to remove some hyperlinks since I don't have enough SO rep to post more than 2 links]

Thanks for your help

Upvotes: 0

Views: 1890

Answers (3)

Nicolas B.
Nicolas B.

Reputation: 7321

Yes SonarQube 5.6 requires Java 8, but that doesn't force you to change the Java version on which Jenkins is running, nor the Java with which you're compiling your code.

If you can switch everything to Java 8 and dump Java 7 then that's the easiest solution. Otherwise Jenkins can manage several JDKs in parallel (JDK installations under Jenkins setting), and then for your SonarQube scan:

  • if you analyse with the SonarQube Scanner, you can choose which JDK the scanner should run with (in the settings, under Execute SonarQube Scanner , previously Invoke Standalone Sonar Analysis)
  • if you analyse with the SonarQube Scanner for Maven (seems to be the case here) then using different JDKs between two Maven steps is not straightforward. Either set-up two different jobs (one for building with a certain JDK and one for scanning with another JDK) or explore the Pipeline alternative (where you can select different JDKs).

Upvotes: 1

Poorna Chander
Poorna Chander

Reputation: 63

Make sure you are running your Jenkins and Sonar on same JDK version. Before upgrading your Jenkins to Java 1.8, make sure your code base is ready for Java 8 migration, if not switch your Sonar to Java 7.

Upvotes: 0

Rodrigo Murillo
Rodrigo Murillo

Reputation: 13642

Make sure the Java version 8 is in your path when you launch Jenkins.

That server probably has Java 7 and 8 installed.

https://wiki.jenkins-ci.org/display/JENKINS/Starting+and+Accessing+Jenkins

Upvotes: 1

Related Questions