Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Providing JDK version in maven goals and options

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

jdk required for maven maven goals and options

like image 269
Kaushambi Suyal Avatar asked Nov 09 '22 23:11

Kaushambi Suyal


1 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:

enter image description here

like image 126
Kraal Avatar answered Dec 31 '22 21:12

Kraal