SonarQube is an open platform to manage code quality. It covers following aspects of a project
- Architecture and Design
- Duplication
- Unit Testing
- Complexity
- Potential Bugs
- Coding Rules
- Comments
There are about 20 plugins available for SonarCube to analyze most of the common programming languages such as Java, C#, C++ etc..
Analyzing a Project with SonarQube Runner
Prerequisites
Prerequisites
- Java should be installed on your machine
- SonarQube download sonarqube-5.0.1.zip
- SonarQube Tunner download sonar-runner-dist-2.4.zip
Extract both SonarQube and SonarQube runner to desired locations. In my machine I've extracted SonarQube to
/home/thusitha/Training/sonarqube-5.0
and SonarQube Runner to
/home/thusitha/Training/sonar-runner-2.4
Inside the SonarQube you can find there are many directories for each platform. Find the matching platform based on your OS.
e.g.
If you are using ubuntu x64 bit OS then you must go to linux-x86-64 directoty
Go to the particular directory through the console and run the Sonar script to start the Sonar sever
Go to the particular directory through the console and run the Sonar script to start the Sonar sever
To start the server run the sonar script in the directory
In Linux
sh sonar.sh console
In Windows
StartSonar.bat
In Linux
sh sonar.sh console
In Windows
StartSonar.bat
Sonar Dashboard http://localhost:9000/
Now go to the project root folder that you want to analyze and create a file and name it as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Required metadata | |
sonar.projectKey=my:project | |
sonar.projectName=org.wso2.training.carbon.order.mgt | |
sonar.projectVersion=1.0 | |
# Path to the parent source code directory. | |
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. | |
# Since SonarQube 4.2, this property is optional if sonar.modules is set. | |
# If not set, SonarQube starts looking for source code from the directory containing | |
# the sonar-project.properties file. | |
sonar.sources=src | |
# Encoding of the source code | |
sonar.sourceEncoding=UTF-8 |
Then we can run SonarQube Runner to analyze the project using this file. To do that run the following command from the location where the created file resides.
On Linux
sonar-runner
On Windows
sonar-runner.bat
No comments:
Post a Comment