# SonarQube Setup
Start by downloading SonarQube from the official website. (opens new window)
Unzip and navigate to the bin directory, you should see multiple folders
Navigate into the folder depending on your current operating system, i.e. linux-x86-64.
Execute the sonar.sh script. Sonar should now startup. After a few seconds, you can navigate to SonarQube within your Webbrowser:
The default admin login is admin:admin.
Navigate to Administration > System > Update Center.
You may now uninstall plugins you do not require like C#.
If you are using Java, you should consider installing PMD, FindBugs and possibly CheckStyle by clicking the Available-Tab. You have to restart SonarQube to apply the changes.
By default, SonarQube launches with an In-Memory database. To have persistent analysis, you need to configure a database. Navigate into the conf directory and open up the sonar.properties file. Edit the following properties:
# Postgres Example
# MySQL Example
The config contains multiple examples for JDBC configuration. Make sure the database exists.
After changing the configuration, restart SonarQube.
# Setting up SonarQube Scanner
The easiest way to analyze your project (opens new window) is using the SonarQube Scanner.
Download the SonarQube Scanner (CLI) (opens new window), which provides a CLI to analyze projects of any language.
Unpack the SonarQube Scanner and navigate into the conf directory. Open up the sonar-scanner.properties.
You are ready to analyze your Multi-Module Maven Project!
# Analyzing the Multi-Module-Maven Project
Imagine we have a Multi-Module Maven Project with the following structure
There are multiple ways of configuring SonarQube for your project. You may define the project settings on the parent-level, or overwrite properties in each module. For the sake of simplicity, let us just define the settings in the parent module.
Create a sonar-project.properties file in the parent folder.
sonar.projectKey=projectKey sonar.projectName=Project Name sonar.projectVersion=1.0 sonar.modules=Module1,Module2,Module3
# Modules inherit properties set at parent level
sonar.sources=src sonar.sourceEncoding=UTF-8 sonar.language=java
You have to define each module in sonar.modules property.
Navigate into the Parent folder and execute Maven and afterwards, execute the Scanner.
mvn clean install
/path/to/sonar-scanner/bin/sonar-scanner -Dsonar.login=admin -Dsonar.password=admin
C:/Apps/sonar-scanner-2.8/bin/sonar-scanner.bat -Dsonar.login=admin -Dsonar.password=admin
By the way, you can also pass the parameter for sonar.host.url in here, if you do not want to edit the sonar-scanner.properties.
When navigating the Projects Administration Page (Adminstration > Projects > Management) (opens new window) you should be able to see your Projects. Click on the project and you should see the results from the analysis.
Go to Issues to see the issues that were analyzed. You can also disable rules under Quality Profiles, if you find rules that do not apply to your project or you do not want to see.
This is it, enjoy static code analysis and improve your code 😃.