Using sonar in your Java Maven project

In my previous post, I went through how to get sonar up and running, now this guide is a quick how to running sonar for your java maven project.

So here is simple maven project DistanceConverter (hardly anything in this project, but enough to run sonar). If you look at the pom.xml file for this project, you will a sonar profile and some properties required for the sonar plugin. To run the sonar code metrics, you need to run

mvn clean install -Psonar sonar:sonar

The “-Psonar” activates the sonar profile and “sonar:sonar” executes the sonar goal in the sonar plugin. If your running this for the first time, expect a long wait as quite a few dependencies may need to be downloaded.

If all goes well, if you go back to the sonar webpage, you will see it’s been updated. You’ll see various metrics e.g. code coverage, the violations reported by checkstyle, pmd and findbugs.

3 Replies to “Using sonar in your Java Maven project”

Leave a Reply

Your email address will not be published.