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

爷,独闯天下 提交于 2019-12-12 02:38:52

问题


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 -> http://i.imgur.com/Jb7Wngu.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 -> http://i.imgur.com/8wJzksI.png

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


回答1:


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




回答2:


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).



回答3:


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.



来源:https://stackoverflow.com/questions/38859098/trying-to-use-sonarqube-on-jenkins-to-analyze-project-but-jenkins-using-jdk-1-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!