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?
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With