You can discover and update the Java-specific properties in the project Administration > General Settings > Languages > Java
.class files are required for java projects with more than one java file. If not provided properly, analysis will fail with the message:
If only some
.class files are missing, you'll see warnings like this:
If you are not using Maven or Gradle for analysis, you must manually provide bytecode to the analysis. You can also analyze test code, and for that, you need to provide tests binaries and test libraries properties.
|Comma-separated paths to directories containing the compiled bytecode files corresponding to your source files.|
|Comma-separated paths to files with third-party libraries (JAR or Zip files) used by your project.|
Wildcards can be used:
|Comma-separated paths to directories containing the compiled bytecode files corresponding to your test files.|
|Comma-separated paths to files with third-party libraries (JAR or Zip files) used by your tests. (For example, this should include the junit jar).|
Wildcards can be used:
Note that the Android development toolchain Jack does not provide
In some situations, you might have to analyze a project built with a different version of Java than the one executing the analysis. The most common case is to run the analysis with Java 11, while the project itself uses Java 8 or before for its build. This case is normally automatically handled when using Maven or Gradle, as well as with any flavor of SonarLint.
If it is your case, and you are not using Maven or Gradle, you will need to set the property
sonar.java.jdkHome manually (see below). By doing this you'll specify which JDK classes the analyzer must refer to during the analysis. Not setting this property, while it would have been required, usually leads to inconsistent or even impossible to fix issues being reported, especially in relation with native JDK classes.
sonar.java.jdkHome, you need to provide the path to the JDK directory used by the project being analyzed, if different from the Java runtime executing the analysis. For example, for a Java 8 project, by setting it as follow:
To enable the JDK preview features in SonarQube, you can set the
sonar.java.enablePreview analysis parameter to
true (default is
The best way to deactivate an individual issue you don't intend to fix is to mark it "Won't Fix" or "False Positive" through the SonarCloud UI.
If you need to deactivate a rule (or all rules) for an entire file, then issue exclusions are the way to go. But if you only want to deactivate a rule across a subset of a file - all the lines of a method or a class - you can use
@SuppressWarnings with rule keys:
Java analysis is able to react to the java version used for sources. This feature allows the deactivation of rules that target higher versions of Java than the one in use in the project so that false positives aren't generated from irrelevant rules.
The feature relies entirely on the
sonar.java.source property, which is automatically filled by most of the scanners used for analyses (Maven, Gradle). Java version-specific rules are not disabled when
sonar.java.source is not provided. Concretely, rules which are designed to target specific java versions (tagged "java7" or "java8") are activated by default in the Sonar Way Java profile. From a user perspective, the feature is fully automatic, but it means that you probably want your projects to be correctly configured.
When using SonarScanner to perform analyses of project, the property
sonar.java.source can to be set manually in
sonar-project.properties. Accepted formats are:
- "1.X" (for instance 1.6 for java 6, 1.7 for java 7, 1.8 for java 8, etc.)
- "X" (for instance 7 for java 7, 8 for java 8, etc. )
If the property is provided, the analysis will take the source version into account, and execute related rules accordingly. At run time, each of these rules will be executed – or not – depending of the Java version used by sources within the project. For instance, on a correctly configured project built with Java 6, rules targeting Java 7 and Java 8 will never raise issues, even though they are enabled in the associated rule profile.
On SonarCloud you can benefit from advanced security rules including XSS vulnerability detection. Java analysis supports analysis of Thymeleaf and JSP views when used with Java Servlets or Spring. To benefit from this analysis you need to make your views part of the project sources using
sonar.sources property. In practice this usually means adding the following in your Maven
or, if you use Gradle:
src/main/webapp is the directory which contains
.jsp or Thymeleaf's
- symbolic-execution: This tag is for rules that reason about the state of the program using data flow analysis. They usually work together to find path-sensitive bugs and vulnerabilities. As soon as an issue is raised, the symbolic execution (SE) analysis of the current path will stop. For that reason, it is not recommended to evaluate these rules independently of each other as it can give a false sense of undetected issues. It is important to keep in mind that SE can never achieve perfection, so we are always working on improving these rules. Finally, note that the Java rules relying on the SE engine operate cross-procedurally in certain circumstances. In particular, all non-overridable methods defined in the same file as the method under analysis and called from within the method's body, will be explored and learned from. Behaviors of overridable methods will be approximated.