sonarqubeSonar is a great tool for ensuring quality and maintainable code. Sonar is like a code reviewer every developer should have. One shouldn’t wait for a formal code review and peer code review to find fault with one’s own code. So, the best way of writing quality code is to run a sonar analysis after coding every major functionality. To do that, once can integrate sonar with the IDE itself. This post is all about running local sonar analysis from eclipse.

Don’t have sonar yet?

If you don’t already have a sonar server installed. Go though this post for quick and painless installation.

Running sonar analysis from eclipse is as easy as setting up sonar in the first place.

Plugin Installation

Step 1: Install a new software to your eclipse using the following
Update Site: http://dist.sonar-ide.codehaus.org/eclipse/

In case the update site doesn’t work, find the latest update site at:
http://docs.codehaus.org/display/SONAR/Installing+SonarQube+in+Eclipse

Check the SonarQube Java and SonarQube optional connectors while installation.

screen1

Step 2: Add a new server to Windows/Preferences/SonarQube/Servers. In case your server is already there, skip this step.

screen2

Step 3: In case a project is already installed. Right click the project in the workspace, click Configure/Associate with SonarQube… . Doing this will make a new option appear in the context menu of the project ‘SonarQube’. In case you see the option even before doing this step, you can skip the step.

screen3

Step 4: In the new option SonarQube, you’ll see two options. Use the ‘Analyze’ option to run sonar locally.
For details of usability of the sonar plugin, see http://docs.codehaus.org/display/SONAR/Working+with+SonarQube+in+Eclipse

screen4

Step 5: Analyze the results. All the issues found in the analysis appear in a window called ‘Sonar Issues’. The analyze options run in a dry run mode, that mean that the results will not be recorded or saved in the database sonar is using. The dry run rsults are also returned as a json file, which can be used to analyze, port results to sonar server as well. The path to this json file is logged in the sonar logs printed in the console window.

screen5

Yes, its done. Use this effectively and stay blessed with quality code.