SONAR – manage your code quality

Posted: October 10, 2011 in Code Quality, Database, Java

Sonar is an open platform to manage code quality. It covers the 7 axes of code quality

7 axes of code quality

7 axes of code quality

Sonar supports a wide range of programming languages such as Java, C, C# etc

Through this article, we are going to see how to set up a Sonar Server and how to integrate a Java Project with it.

Prerequisites

  1. MySQL 5.1
  2. Maven 2.2.1 or higher
  3. Sonar Server

Let’s start !!

Download Sonar server from the Sonar Website and unzip it.

Prior to starting the Sonar server, we need to start the MySQL Server.

Now that MySQL server is up, we need to configure it to the Sonar Server

Navigate to /conf and open sonar.properties in notepad++.

sonar.properties

sonar.properties

and remember to give this configuration as well (our MySQL database URL)

sonar.properties

sonar.properties

Now that the server is configured, lets start the Sonar Server.

Remember, Sonar is a web-based application.

 

 

 

 

 

 

Don’t worry if you doesn’t see any change in the console. Nothing gets printed on this console.

Instead, we have to check the sonar.log available under <sonar installation directory>/logs

In the logs, you will see

2011.09.15 11:20:50 INFO  org.sonar.INFO  Enable profiles…
2011.09.15 11:20:50 INFO  org.sonar.INFO  Enable profiles done: 93 ms
2011.09.15 11:20:50 INFO  org.sonar.INFO  Activate default profile for c
2011.09.15 11:20:50 INFO  org.sonar.INFO  Activate default profile for java
2011.09.15 11:20:50 INFO  org.sonar.INFO  Register quality models…
2011.09.15 11:20:50 INFO  org.sonar.INFO  Register quality models done: 0 ms
2011.09.15 11:20:50 INFO  org.sonar.INFO  Start services done: 41066 ms

This “Start services done” in the above log  means the server is up and ready for servicing.

Now that the server is up and running, lets integrate the Java Project that we created earlier using Maven (hope you know how to create Simple Java Project using maven)

Goto the Java project root in command prompt and execute the following maven command

mvn sonar:sonar

The console will say Build Successful.

Once you see this message, open Firefox or IE and navigate to the URL

http://localhost:9000

Sonar Console

Sonar Console

 

 

 

 

 

 
This console will list all the Projects that we integrated

Comments
  1. [...] SONAR – manage your code quality By ShamanOfJava, 10 October 2011 Sonar is an open platform to manage code quality. It covers the 7 axes of code quality. Sonar supports a wide range of programming languages such as Java, C, C# etc. Through this article, we are going to see how to set up a Sonar Server and how to integrate a Java Project with it. [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s