Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 23 Next »

Table of Contents



Maven 2.0.10, 2.1.x, 2.2.x or 3.x


Global settings

Sonar can use a Maven plugin to perform project analysis : this is the easiest and most comprehensive way. To do so, you should edit settings.xml file, located into $MAVEN_HOME/conf or ~/.m2, and the database parameters to be used as well as the Sonar server URL.

Example :


Warning : With Sonar 2.2, the property MUST NOT end with a slash character. Otherwise, JDBC driver is not found by the Sonar Maven plugin. See SONAR-1685.

It is recommended to increase the Java heap memory. It avoids getting OutOfMemoryError failures. Set the MAVEN_OPTS environment variable :

Project settings

For advanced features such as reusing existing unit test reports, you can define advanced parameters. These parameters can be defined :

  • in the Maven command-line (see next section) : 

  • in the properties section of pom.xml :

Note that command-line properties override pom properties.

Analyze Maven projects

Analyzing a maven project consists of running a maven goal in the directory where the pom.xml sits. If possible, an install goal should be performed prior to the sonar one.

Recommended way

Using Eclipse


Make sure you're not using the eclipse plugin maven embedder. Define a new maven runtime pointing to your local maven install, use the latest maven eclipse plugin and uncheck "resolve workspace artifacts" in the maven project launch window.
Have a look at the first comment of this ticket :

Advanced Reactor Options


Note that Advanced Reactor Options (such as "--projects" and "--resume-from") not supported by Sonar and should not be used.

Alternative way

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 Sonar. Do not use the -Dtest=false parameter, else Sonar will not execute unit tests and therefore not report on them.

The -Dmaven.test.failure.ignore=true is there to make sure that event if unit tests fail, the analysis will happen

How to fix version of Maven plugin

Read this page for more details.

Reuse existing unit test reports

If you generates JUnit and Cobertura/Clover/Emma reports with your build mechanism you can configure Sonar in order to collect them. To do that, you must add the following lines in your pom.xml file:

The property sonar.cobertura.reportPath can be replaced by sonar.clover.reportPath if you use Clover instead of Cobertura.

  • No labels