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 32 Next »

This bootstrapper is recommended to run analysis on Maven projects.

Table of Contents

Prerequisite

You must have previously installed and configured Maven.

Analyze a Maven Project

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

skipTests=true not to run unit tests twice: during the install goal and again during the sonar goal. You can also deactivate the integration tests execution. Please refer to the Maven documentation.

 

Using Eclipse

Icon

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 : http://jira.codehaus.org/browse/SONAR-929

Advanced Reactor Options

Icon

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 DskipTests=true parameter, otherwise 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

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.

How to fix version of Maven plugin

It is recommended to lock down versions of Maven plugins. Two versions of the Sonar maven plugin exist, one for Maven 2 and one for Maven 3. Fixing its version depends on the Maven versions used to analyse the project :

Project analyzed with Maven 2 only

Add the following code to pom.xml :

<build>
  <pluginManagement>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>sonar-maven-plugin</artifactId>
      <version>1.0</version>
    </plugin>
  </pluginManagement>
</build>
Icon

The version 1.0-beta-1 is not supported anymore.

Project analyzed with Maven 3 only

<build>
  <pluginManagement>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>sonar-maven-plugin</artifactId>
      <version>2.0</version>
    </plugin>
  </pluginManagement>
</build>

Project analyzed with both Maven 2 and Maven 3

<build>
  <pluginManagement>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>sonar-maven-plugin</artifactId>
      <version>${sonarVersion}</version>
    </plugin>
  </pluginManagement>
</build>
<profile>
  <id>maven-2</id>
  <activation>
    <file>
      <!-- basedir expression is only recognized by Maven 3.x (see MNG-2363) -->
      <missing>${basedir}</missing>
    </file>
  </activation>
  <properties>
    <sonarVersion>1.0</sonarVersion>
  </properties>
</profile>
<profile>
  <id>maven-3</id>
  <activation>
    <file>
      <!-- basedir expression is only recognized by Maven 3.x (see MNG-2363) -->
      <exists>${basedir}</exists>
    </file>
  </activation>
  <properties>
    <sonarVersion>2.0</sonarVersion>
  </properties>
</profile>

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