I am using sonar 4.5.1 and it is compatible with JDK 1.7 and above .For the projects which are on JDK1.6 in Jenkins , I want to perform sonar analysis using JDK1.7. To achieve this under Jenkins , in maven goals and options , I am using -Dsonar.java.source= jdk1.7.0_76 but during build it seems that jdk1.7.0_76 is not being picked for sonar analysis. Sonar Analysis is still being done with the JDK 1.6 version which is defined in JDK section in Jenkins. This results to the build error : "The plugin findbugs is not supported with Java 1.6.0_26" . I don't want to use the sonar in post build action because it throws some other error so I want to provide the sonar details in maven goals and options only. Why is jdk1.7.0_76 not being picked? What am I missing? Is there any other way of providing the JDK1.7 version?
(Edited)
My requirement : maven analysis should be done using jdk 1.6 and sonar analysis should be done with jdk 1.7 and above (sonar analysis step is provided in maven goals and no Sonar-postbuild action is used)
under Maven goals and options
clean install -Dmaven.test.skip=true -Dsonar.jdbc.url=jdbc:postgresql://sonardb.test.com:5555/sonar -Dsonar.host.url=http://localhost:9000/sonar -Dsonar.java.target=jdk1.8.0_40 -Dsonar.java.source=jdk1.8.0_40 org.codehaus.mojo:sonar-maven-plugin:1.0:sonar -Dsonar.branch=test
Please find below the screenshots

- 213
- 4
- 17
3 Answers
Have a look at your mvn
script:
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
This change is done at the level of your Maven environment. Before launching Maven, you need to set the JAVA_HOME
environment variable to the location of your JDK version 1.7.
I guess that you're using an execute shell
post-build step. If you're using bash
you just need to type JAVA_HOME="path to your JDK 1.7 home"
before the line containing your mvn
command in the command
text area of your Jenkins' job configuration as follows:

- 2,779
- 1
- 19
- 36
-
please find the edited question with added screenshots. – Kaushambi Suyal Dec 16 '15 at 07:37
-
If you want to run analysis using an alternate jdk you HAVE to use a post step! – Kraal Dec 16 '15 at 09:41
-
Do you mean to say that this parameter doesn't work : -Dsonar.java.target=jdk1.8.0_40 -Dsonar.java.source=jdk1.8.0_40 if provided in Goals and Options ? – Kaushambi Suyal Dec 16 '15 at 09:48
-
See http://stackoverflow.com/questions/24289704/sonarqube-java-version-used-to-verify-code . If you need to run SQ using an alternate JDK version (which is your case as your code needs to be built using JDK 1.6 and SQ needs JDK1.7+), you have to run Maven in an alternate process using this alternate JDK version in order to analyse the code with the expect JDK. This can be done in Jenkins using the SQ plugin for Jenkins or by using an ``execute shell`` post step as described in my answer. – Kraal Dec 16 '15 at 10:29
-
I fail to relate your answer to my question. When sonar analysis is already being done in goals and options, how would post step help ? We need some syntax after maven analysis and before sonar analysis that should pick the different version of jdk? Also, we only have rights in Jenkins config page, not to code files, so I would request you to provide the solution which could be used on Jenkins. Already we definitely do have SQ plugin for Jenkins. – Kaushambi Suyal Dec 16 '15 at 11:37
-
kindly reply to my comment above. – Kaushambi Suyal Dec 17 '15 at 11:27
You need to run the analysis with Java 7 or higher. The sonar.java.source
property simply tells the analyzer what Java version your code is compatible with.
You're free to compile your code with Java 6 (or lower), but the scanner (whether that's SonarQube Scanner, SonarQube Scanner for Maven, ...) must run with Java 7.

- 22,346
- 4
- 40
- 76
-
I am not using sonar-runner here. As I mentioned in mail, I do know that analysis should be done with Java 7 or higher but what is the right way (syntax) of providing in maven goals and options as the one I mentioned is not being accepted during build. – Kaushambi Suyal Dec 14 '15 at 12:46
-
You may need to update $JAVA_HOME just before & right after the analysis – G. Ann - SonarSource Team Dec 14 '15 at 14:04
Though this is an old question still answering for other's benefit:
If you go to configure page of your Job and Click on "Advance" button for Sonar plugin, you will have an option to select JDK for the same as desplyed below select JDK 7 which should be already configured for your Jenkins (for this you may go to Manage Jenkins):

- 53
- 2
- 5