Go, Get, Run SonarQube

 

SonarQube

                             In the last article we introduced SonarQube. In this article we will setup the SonarQube and start analyzing the code. Follow the below steps to setup.

Step 1: Download the latest version of SonarQube. As of now the latest version is 5.0.1. After downloading, unzip it and the folder structure will be as shown below.

SonarQube Folder Structure

Step 2: SonarQube uses database to store the settings, rules, metrics, issues etc… It supports MSSQL Server, MySql, Oracle and PostgreSQL. In this article we are going to use MySql. We will create a database and assign the privileges to it.

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar123';
GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar123';
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar123';

Step 3: Goto the “conf” folder (see Step 1) and configure the database details as part of sonar.properties file as shown below.

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar123
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

Step 4: Goto the “bin” folder (see Step 1) and choose the right operating system folder to start the Sonar. I have chosen “windows-x86-64” and clicked on “StartSonar.bat”. First time it will take some time to start as it is going to create tables in the configured database and setting up the default data. The sonar server runs on 9000 port by default and the sonar host URL will be http://localhost:9000

Step 5: Download the SonarQube Runner to analyze the code, unzip it and  set the SONAR_RUNNER_HOME environment variable to the root folder of Sonar Runner.

Step 6: Set the PATH variable to SONAR_RUNNER_HOME/bin and ensure the JAVA_HOME set properly.

Step 7: Move to your projects root folder and create sonar.properties file and add the below properties.

sonar.projectKey=techDetectorArch
sonar.projectName=techDetectorArch
sonar.projectVersion=1.0
sonar.sources=src
sonar.host.url=http://localhost:9000
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar123
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

Step 8: Run the below command to start analyse the code from the projects root folder.

sonar-runner -Dproject.settings=sonar.properties

If it goes successful, you will see the below log.

21:05:17.039 INFO - ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/techDetectorArch
21:05:17.039 INFO - Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report.
21:05:17.055 INFO - Executing post-job class org.sonar.plugins.core.issue.notification.SendIssueNotificationsPostJob
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
Total time: 18.283s
Final Memory: 17M/716M
INFO: ------------------------------------------------------------------------

Step 8: Goto http: //localhost:9000 to see the sonar’s dashboard, where all the metrics will be available.

SonarQube Dashboard

 

That’s it. You are having Sonar up & running.

Advertisements

I am Siva Prasad Rao Janapati. Working as a software developer. Has hands on experience on ATG Commerce(DAS/DPS/DCS), Mozu commerce, Broadleaf Commerce, Java, JEE, Spring, Play, JPA, Hibernate, Velocity, JMS, Jboss, Weblogic,Tomcat, Jetty, Apache, Apache Solr, Spring Batch, JQuery, NodeJS, SOAP, REST, MySQL, Oracle, Mongo DB, Memcached, HazelCast, Git, SVN, CVS, Ant, Maven, Gradle, Amazon Web services, Rackspace, Quartz, JMeter, Junit, Open NLP, Facebook Graph,Twitter4J, YouTube Gdata, Bazzarvoice,Yotpo, 4-Tell, Alatest, Shopzilla, Linkshare. I have hands on experience on open sources and commercial technologies.

Tagged with: , ,
Posted in Code Quality

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 )

Google+ photo

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

Connecting to %s

DZone

DZone MVB

Java Code Geeks
Java Code Geeks
%d bloggers like this: