Providing JDK version for maven goals and options

I am using sonar 4.5.1 and compatible with JDK 1.7 and above. For projects that are on JDK1.6 in Jenkins, I want to perform sonar analysis using JDK1.7. To achieve this in Jenkins, for the purposes and options of maven, I use -Dsonar.java.source = jdk1.7.0_76, but at build time it seems that jdk1.7.0_76 is not selected for sonar analysis. Sonar analysis is still performed with the JDK version 1.6, which is defined in the JDK section in Jenkins. This results in a build error: "Findbugs plugins are not supported by Java 1.6.0_26." I do not want to use sonar in post post action, because it causes a different error, so I want to provide sonar information only for the purposes and options of maven. Why is jdk1.7.0_76 not selected? What am I missing? Is there any other way to provide JDK1.7 version?

(Edited)
My requirement: maven analysis must be performed using jdk 1.6, and sonar analysis must be performed using jdk 1.7 and higher (the sonar analysis step is provided for maven purposes and no Sonar-postbuild action is used)
in accordance with Maven goals and parameters
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

Below are screenshots

jdk is required for maven maven goals and parameters

+5
source share
3 answers

Take 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 made at the level of your Maven environment. Before starting Maven, you need to set the JAVA_HOME environment variable to the location of your version 1.7 of the JDK.

I assume that you are using the execute shell post-build step. If you use 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 ​​the Jenkins job configuration as follows:

enter image description here

+1
source

You need to run the analysis with Java 7 or higher. The sonar.java.source property simply tells the analyzer which version of Java your code is compatible with.

You can compile your code using Java 6 (or below), but the scanner (whether it is a SonarQube scanner, SonarQube Scanner for Maven, ...) should work with Java 7.

0
source

Although this is an old question that is still responsible for other benefits:

If you go to customizing your assignment page and click the "Advance" button for the Sonar plugin, you will have the opportunity to select the JDK for the same as below, select the JDK 7, which should already be configured for your Jenkins (for this you can go to Jenkins Office):

Screenshot of the Sonar Plugin in the Job Configuration section

0
source

Source: https://habr.com/ru/post/1238073/


All Articles