Maven Sonar plugin for your Java project
I needed to add Sonar reporting to a small Java project that uses Maven for the build. There is a Maven Sonar plugin available for this task here.
First add sonar properties file ( sonar-project.properties ) to your java project, put it in root.
sonar.projectKey=javaTest
sonar.projectVersion=1.0
sonar.projectName=Sample java spring MVC project
# Comma-separated paths to directories with sources (required)
sonar.sources=src
# Language
sonar.language=java
# Encoding of the source files
sonar.sourceEncoding=UTF-8
Make Maven aware of the Sonar location etc, add that to the Maven settings \maven\conf\settings.xml
Something like this
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!– SERVER ON A REMOTE HOST –>
<sonar.host.url>http://remotebox.com:9000</sonar.host.url>
<sonar.jdbc.url>jdbc:h2:tcp://remotebox.com:9092/sonar</sonar.jdbc.url>
</properties>
</profile>
For Maven version 3+ add this to the POM file in the build section, else Maven version 2 ( below ).
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
For Maven 2.
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
Pass the sonar:sonar goal to the Maven script then kick off a build, the dependencies should be downloaded automatically. The report for your project displays on the Sonar server dashboard.