SonarQube Installation and Configuration
The Use-Case Scenario
The use-case is a two step assessment of the source code being developed in a software project for maintaining coding standards, prevention of potential bugs, maintaining an acceptable comments ratio etc.
Step 1 : (Before checking in Source Code)
At the development stage, developer will use SonarQube plugins (Sonar Lint) for real time assessment of his/her code quality. Hence he/she can refactor it before uploading to the main repository.
Step 2 : (After checking in Source Code)
When there is a new commit to the source code repository, whole repository will get analyzed and the results will be displayed in the SonarQube dash board.
Installation
Prerequisites : JAVA, Apache Maven (Latest Version), Database Server of your choice (MySQL will be used in this article)
Configuring System paths
Key | Value |
JAVA_HOME | C:\Program Files\Java\jdk1.8.0_25 |
M2_HOME | C:\repo\apache-maven-3.3.9 |
SONAR_RUNNER_HOME | C:\repo\sonar-runner-2.4 |
Path | C:\Program Files\Java\jdk1.8.0_25\bin |
Path | C:\repo\apache-maven-3.3.9\bin |
Path | C:\repo\sonar-runner-2.4\bin |
(Please note that this table contains sample install locations and the Values for the system paths should be pointed to the exact installation locations.)
Configuring the Databse
(Though it's possible to work with the embedded H2 database in the SonarQube server, it is recommended to configure separate database before running analyzes)
Just download and run the following .sql query in the mysql console.
create_database_and_users.sql
Which will create,
A Database as : sonar
An User as : sonar
An User password as : sonar
Configuring Sonar Analyzer
sonar.properties
Copy and Replace in - C:\repo\sonarqube-5.4\conf\sonar.properties
sonar-runner.properties
Copy and Replace in - C:\repo\sonar-runner-2.4\conf\sonar-runner.properties
(It is assumed that MySQL server installed locally in port 3306 and database name, user, password is set to value "sonar". If it is not, kindly open the copied files and perform changes where necessary)
Running SonarQube Server
Visit C:\repo\sonarqube-5.4\bin\ folder and run the StartSonar.bat or sonar.sh to start the SonarQube server.
E.g. : Windows OSx64 - C:\repo\sonarqube-5.4\bin\windows-x86-64\StartSonar.bat
Linux OSx64 - /home/Documents/repo/sonarqube-5.4/bin/linux-x86-64/sonar.sh
Once the server is up and running, visit URL http://localhost:9000/. You shall see the following screen.
Whenever you get to see the above message, you should configure sonar qube (if you are the administrator for SonarQube Server). In order to do so visit http://localhost:9000/setup and click on "Upgrade" button.
Then the following screen will appear and you should give it some time to run updates on the database server.
Once it finishes the update it will automatically be redirected to http://localhost:9000/ (You should see a screen similar to the following snapshot)
Next and final step will be to try logging in to the SonarQubeServer as the administrator. For that, use following credentials,
user name : admin
password : admin
If the above screen appeared (with user name as "Administrator" on the top-right corner), which means you have finished configuring SonarQube server.
Hoooooooooooooooorah !!!!
If you want to analyze your source code straight away > Part 3 - Continues Inspection With Sonar (The Sonar Way)
If you want to configure Sonar Plugin for eclipse > Part 4 - Sonar Plugin Installation and Configuration for Eclipse IDE
If you want to configure Sonar Plugin for eclipse > Part 4 - Sonar Plugin Installation and Configuration for Eclipse IDE