Analyzing a Maven project consists of running a Maven goal in the directory where the pom.xml file sits. If possible, an
install goal should be performed prior to the
mvn clean install -DskipTests=true mvn sonar:sonar
skipTests=true not to run unit tests twice: during the
install goal and again during the
sonar:sonar goal. You can also deactivate the integration tests execution. Please refer to the Maven documentation.
Make sure you're not using the eclipse Eclipse plugin maven embedder. Define a new maven Maven runtime pointing to your local maven Maven install, use the latest maven eclipse plugin and uncheck "resolve workspace artifacts" in the maven project launch window.
Note that Advanced Reactor Options (such as "--projects" and "--resume-from") are not supported by Sonar SonarQube and should not be used.
When the above configuration is not possible, you can run an analysis in one command, but unit tests will run twice: once in the
install goal and once in the
sonar:sonar one. Do not use the
DskipTests=true parameter, otherwise Sonar will not execute unit tests and therefore not report on themthe unit tests will be executed at all.
mvn clean install sonar:sonar -Dmaven.test.failure.ignore=true
-Dmaven.test.failure.ignore=true is there to make sure that even if some unit tests fail, the Sonar SonarQube analysis will be performed.
A pom.xml file sample is available here.
Additional analysis parameters are listed on the Analysis Parameters page.
Since Sonar SonarQube 3.4, if the a project cannot be accessed anonymously, the '
sonar.login' and '
sonar.password' properties are required to run an analysis on this project. These properties have to be set to the credentials of a user having the 'User' role on this project. You can set them either:
- directly on the command line by adding
- or in the pom.xml file
- or in the Maven profile (settings.xml file)
A project cannot be anonymously accessed when either:
How to Fix Version of Maven Plugin
Analyzing a Multi-module and Multi-language Project
Since Sonar SonarQube 3.3, it is possible to run an analysis on a multi-module project whose modules contains source code from different languages.
To do so, just add the '
sonar.language' property to the pom of each module.