SonarQube Tutorial explains about how to install /configure SonarQube server for continuous integration and improving code quality.
It helps for various tasks and provide reports on duplicated code, coding standards, unit tests, code coverage, complex code, potential bugs, comments and design and architecture.
SonarQube is internally using PMD,Findbugs,CheckStyle etc. You can add additionally plugins according to your requirement
Setup / Configure Sonar
SonarQube Installation Steps:
You can follow below steps in order to installing Sonar Java Code Analysis Tool. Which will dramatically imporve code quality.
Now, You can see sonar server is started
- Copy and unzip sonar.zip and sonar-runner.zip
- Start the Sonar server using the script available in SONAR_HOME\bin\windows-x86-32\StartSonar.bat (OS dependent)
- After starting the server you can browse to http://localhost:9000
Creating Project & Analysing Using Sonar
For setting environment variable, you can do following steps
Also append C:\sonar\sonar-runner-2.3\bin to Path.
# Required metadata sonar.projectKey=java-sonar-runner-simple sonar.projectName=Simple Java project analyzed with the SonarQube Runner sonar.projectVersion=1.0 # Comma-separated paths to directories with sources (required) sonar.sources=src # Language sonar.language=java # Encoding of the source files sonar.sourceEncoding=UTF-8
- Set a new environment variable as SONAR_RUNNER_HOME. And its value should be C:\sonar\sonar-runner-2.3 (unzipped path of sonar-runner.zip)
- From the Desktop, right click on My Computer and click Properties.
- Click Advanced System Settings link in the left column.
- In the System Properties window click the Environment Variables button.
- Inside System variable, click on New Button
- Create a new Java Project and add below sonar-project.properties file into the root of the project folder (see below project strcuture)
- Using the terminal go the project home and run the command sonar-runner (Sonar Server must be started)
- After the success run browse the web http://localhost:9000 where you can see the report related to the project