SonarQube (formally known as just sonar) is a server based open source platform for inspecting code quality of a project. It's mainly designed to inspect continuous code quality of projects with multi developer environment. But it can be use to inspect code quality in individual projects as well.
In this short tutorial I'll explain how to use sonar in single developer environment to inspect code quality of a java project.
I have used following configurations to up and running SonarQube.
Mac OS X (10.9.4)
Mysql
Maven 3.0
JDK 1.6 or Above
Sonar 4.4.1
1. Download, Install and run SonarQube
It's open source..!! you can download it free from sonar website.
SonarQube download [1]. Unzip somewhere you can reach.
Set the SONAR_HOME path to sonar qube base directory using .profile or .bashrc scripts.
2. Create Mysql database for SonarQube
Source following script on mysql to create new database for sonar sonar database script [2]. This is essential as it keeps all data related to projects on this database.
Make sure it's created properly by login to Mysql server.
3. Set up SonarQube
Goto sonarQube conf directory using "cd $SONAR_HOME"/conf and open sonar.properties file using vim.
Note down sonar .jdbc username and password this is the username and password.
Uncomment sonar.jdbc.url to enable jdbc driver for mysql database.
4. Set up maven to run sonar upon build.
Move to .m2 directory using following command.
Create a new file settings.xml.
Save following xml as settings.xml using vim.
Change your mysql root username and password accordingly and add localhost to sonar.host.url.
5. Run sonar server.
Move to sonar bin directory.
Run the sonar sever as follows.
Now using a web browser goto following url http://localhost:9000/ . Hopefully now you should see the sonar dashboard.
6. Inspect a project using SonarQube.
From CLI move to root directory of your project (where the main pom file is) and run following command.
After build success using a web browser open sonar dashboard and you will see your newly build project under "Projects" tab.
Congratulations.. now you can use sonar for inspect quality of your code every time you build it.
Goto sonarQube conf directory using "cd $SONAR_HOME"/conf and open sonar.properties file using vim.
Uncomment sonar.jdbc.url to enable jdbc driver for mysql database.
4. Set up maven to run sonar upon build.
Move to .m2 directory using following command.
Create a new file settings.xml.
Save following xml as settings.xml using vim.
Change your mysql root username and password accordingly and add localhost to sonar.host.url.
5. Run sonar server.
Move to sonar bin directory.
Run the sonar sever as follows.
6. Inspect a project using SonarQube.
From CLI move to root directory of your project (where the main pom file is) and run following command.
After build success using a web browser open sonar dashboard and you will see your newly build project under "Projects" tab.
Congratulations.. now you can use sonar for inspect quality of your code every time you build it.
References :
No comments:
Post a Comment