News and Notes from the Makers of Nexus | Sonatype Blog

Maven 3 and Sonar

Written by Anders Hammar | August 16, 2010

Another step towards a final release of Maven 3.0 was made the other day when version 3.0-beta-2 was released. I’ve been using Maven 3 since its alpha days, and despite the alpha/beta moniker, I find it to be superior to any Maven 2.x version. If you are starting a new project, I strongly recommend using Maven 3.

That being said, in the complete development environment there are a few missing pieces when working with Maven 3. One of these is getting Sonar to work with Maven 3, which had not been possible until the latest version of Sonar was released.

This post will explain how to get Maven 3 and Sonar to work together.


To get started, the first thing you must do is install Sonar 2.2 and Maven 3.0-beta-1 or later. No extra configuration of Sonar is required for Maven 3, and the same configuration of properties in Maven also applies. Please note that the URL for the Sonar server -- sonar.host.url -- must not end with a slash character.

The difference when using Maven 3 lies in the Maven plugin. Currently, the plugin at Codehaus Mojo doesn’t work with Maven 3, so you need to use the one at the Sonar project instead.

Now, in your Maven project, execute the command below. Until the Sonar Maven plugin at Codehaus Mojo is updated with Maven 3 support, this is the command to use:

mvn org.codehaus.sonar:sonar-maven3-plugin:2.2:sonar

Your project should now be analyzed and the result uploaded to Sonar.

One thing to be aware of is that you need to align the version of sonar-maven3-plugin with the version of Sonar that is installed. When you upgrade Sonar, you need to change the version on the Maven side as well.

To view the progress of Maven 3 support in the plugin at Codehaus Mojo, follow MOJO-1545.