Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This analyzer is recommended to launch analysis on Java Maven project.

Prerequisites

...

A pom.xml file sample is available here.

Additional analysis parameters are listed on the Analysis Parameters page.

See also some complete examples here.

Security

Since Sonar 3.4, if 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 -Dsonar.login=myUser -Dsonar.password=myPassword
  • or in the pom.xml file
  • or in the Maven profile (settings.xml file)

A project cannot be anonymously accessed when either:

Sample Projects

To help you getting started, a simple project sample is available on github that can be browsed or downloaded: projects/languages/java/maven/java-maven-simple

How to Fix Version of Maven Plugin

...

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

...

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

...

No Format
<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>${sonarVersion}</version>
      </plugin>
    <plugins>
  </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>

Analyzing a Multi-module and Multi-language Project

Since Sonar 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.

To help you getting started, a multi-language project sample is available on github that can be browsed or downloaded: projects/languages/multi-language/multi-language-java-javascript-maven