Thursday, 22 October 2015

How to configure Sonar ?

Its really very important to maintain the code quality as a developer. Sonar is an open platform to manage code quality. 

How to configure Sonar ?


Its really not very easy, but bit tricky. Follow the below steps to configure the your local machine. I have used Linux (Ubuntu) machine to do this setup.

Download the Sonar. I have downloaded the verion sonar-3.7.3.
 
Then unzip the downloaded file and go to the /bin directory. You can go to any of the below folders as per your machine architecture.


dev@xxx-developer bin # ls -ltr
total 44
drwxrwxrwx 3 root java 4096 Oct  9 11:51 linux-x86-32
drwxrwxrwx 3 root java 4096 Oct  9 11:51 macosx-universal-32
drwxrwxrwx 3 root java 4096 Oct  9 11:51 solaris-sparc-64
drwxrwxrwx 3 root java 4096 Oct  9 11:51 windows-x86-32
drwxrwxrwx 3 root java 4096 Oct  9 11:51 solaris-sparc-32
drwxrwxrwx 3 root java 4096 Oct  9 11:51 linux-ppc-64
drwxrwxrwx 2 root java 4096 Oct  9 11:51 jsw-license
drwxrwxrwx 3 root java 4096 Oct  9 11:51 macosx-universal-64
drwxrwxrwx 3 root java 4096 Oct  9 11:51 windows-x86-64
drwxrwxrwx 3 root java 4096 Oct  9 11:51 solaris-x86-32
drwxrwxrwx 3 root java 4096 Oct 23 00:04 linux-x86-64

Here I am using 64bit linux, so I am using linux-x86-64.

/usr/java/sonar-3.7.3/bin/linux-x86-64

Now, start the Sonar.
dev@xxx-developer linux-x86-64 # ./sonar.sh start
Starting sonar...
Removed stale pid file: /usr/java/sonar-3.7.3/bin/linux-x86-64/./sonar.pid
Started sonar.
dev@xxx-developer linux-x86-64 # pwd
/usr/java/sonar-3.7.3/bin/linux-x86-64

Now check on the browser for whether sonar is running on not.

http://localhost:9001/



Normally it runs over 9001 port always. You can also configure this port  /conf folder.

/usr/java/sonar-3.7.3/conf/sonar.properties

#---------------------------------------------------------
# WEB SETTINGS - STANDALONE MODE ONLY
# These settings are ignored when the war file is deployed to a JEE server.
#---------------------------------------------------------
# Listen host/port and context path (for example / or /sonar). Default values are 0.0.0.0:9000/.
#sonar.web.host:                           0.0.0.0
sonar.web.port:                           9001


You can check the status for sonar is running or not .

dev@xxx-developer linux-x86-64 # ./sonar.sh status

sonar is running (20135).


Maven Settings :-

Setting in Maven settings.xml :-

      <profile>
        <id>sonar</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
                    <sonar.host.url>http://localhost:9001</sonar.host.url>
        </properties>
    </profile>


This above maven setting is required if you want to run the sonar from maven build. While building the maven project from terminal as sample below :

dev@xxx-developer ~/lar_rollback_service $ mvn clean install sonar:sonar 


Project Specific Report :-


Code Coverage Report :-







Hope it will help you. Happy and quality development.


Follow for more details on Google+ and @Facebook!!!



See More  -