See https://docs.sonarqube.org/display/SONAR/Documentation for current functionality
This analyzer is recommended to launch analysis on Java Maven project.
You must have previously installed and configured SonarQube Scanner for Maven and read Analyzing Code Source.
Analyzing a Maven Project
Analyzing a Maven project consists of running the Maven goal
sonar:sonar in the directory where the pom.xml file sits after having compiled and executed tests:
In some situation you may want to run
sonar:sonar goal as a dedicated step. Be sure to use 'install' in the first step to have proper dependency resolution in multi-module projects. Also be aware that additional source folders registered by a plugin (for example build-helper) will not be taken into account during the SonarQube analysis in this case:
If you need to use a specific version of the SonarQube Maven plugin instead of using the latest:
See also 'How to Fix Version of Maven Plugin' below.
To get coverage information, you'll need to generate the coverage report before the analysis. See Java Unit Tests and Coverage Results Import and Code Coverage by Integration Tests for Java Project for more information.
Configuring the SonarQube Analysis
A pom.xml file sample is available here.
Additional analysis parameters are listed on the Analysis Parameters page.
Any user who's granted Execute Analysis permission can run an analysis. If the Anyone group is not granted Execute Analysis permission or if the SonarQube instance is secured (the Note that for a preview analysis, the user also has to be granted the Browse permission on the project to be analyzed.
sonar.forceAuthentication property is set to
true), the credentials of a user having been granted Execute Analysis permission have to be provided through the
sonar.password properties. Example:
sonar-runner -Dsonar.login=myLogin -Dsonar.password=myPassword
Any user who's granted Execute Analysis permission can run an analysis.
If the Anyone group is not granted Execute Analysis permission or if the SonarQube instance is secured (the
Note that for a preview analysis, the user also has to be granted the Browse permission on the project to be analyzed.
Excluding a module from SonarQube analysis
You can either:
- define property
pom.xmlof the module you want to exclude
- use build profiles to exclude some module (like for integration tests)
- use Advanced Reactor Options (such as "-pl"). For example mvn sonar:sonar -pl !module2
How to Fix Version of Maven Plugin
It is recommended to lock down versions of Maven plugins:
Project analyzed with Maven 3
Analyzing a Multi-language Project
By default the
sonar.sources property is set to the value of the Maven
sourceDirectory property (by default it is src/main/java) plus
pom.xml (and also
src/main/webapp is automatically added for
war modules). Therefore, for a multi-language project, the property usually has to be overridden to:
Converting a Mono-language Project to a Multi-language Project
The first step is to choose which one of these two mono-language projects you will convert to a multi-language project. You will lose the history (timeline, false positives, action plans, etc.) on the one that won't get converted to a multi-language project. In this example, we'll choose to convert the Java project to a multi-language project as most of our code (and therefore history) is Java.
The second step is to run another analysis of this Java project the old way (make sure to explicitly set the
sonar.language property to
java). This step is mandatory to keep the history on the project.
The third and last step is to remove the
sonar.language property and set the