Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube Java version used to verify code

Tags:

java

sonarqube

How can I know against which version of Java SonarQube validates the code? Is it the version of the JVM? What then if my project is based on a different version?

like image 311
algiogia Avatar asked Jun 18 '14 15:06

algiogia


People also ask

Does SonarQube work with Java 8?

The only prerequisite for running SonarQube is to have Java (Oracle JRE 8 or OpenJDK 8) installed on your machine. Note: On Mac OS X it is highly recommended to install Oracle JDK 8 instead of the corresponding Oracle JRE since the JRE installation does not fully set up your Java environment properly.

Does SonarQube support Java 17?

In SonarQube 9.4, Java 17 is supported for running analysis, and parsing of Java 18 code (and 17, too) is also supported. Regarding the version of Java your code runs with, as long as you analyze with a supported version of Java, you can compile with or to whatever version of Java you like.

How do I run SonarQube with Java 11?

Set Execute SonarQube Scanner JDK version If you're using the Execute SonarQube Scanner step in your configuration, you can set the JDK for this step in the configuration dialog. This allows you to use JDK 11 for the code scanning performed by SonarQube and the globally configured JDK for all other steps in the job.


2 Answers

The default value is 1.5.

To set the appropriate version, you need to set sonar.java.source property to tell PMD which version of Java your source code complies to.

Possible values: 1.4, 1.5 or 5, 1.6 or 6, 1.7 or 7. Since version 2.2 of the plugin, this property can also be set to 1.8 or 8.

If you're using the ant task, just add:

 <property name="sonar.java.source" value="${javaversion}"/> 

If you're using the SonarRunner, just add the line below to the file <install_directory>/conf/sonar-runner.properties:

sonar.java.source=1.5
like image 93
edubriguenti Avatar answered Oct 22 '22 02:10

edubriguenti


I do confirm that this property sonar.java.source is used only by the PMD tool. The SonarSource's Java analyser uses a superset grammar and so can analyse source files regardless of the Java version they comply to.

like image 43
Freddy - SonarSource Team Avatar answered Oct 22 '22 02:10

Freddy - SonarSource Team