Install SonarQube

Because the main aim of GSoC is to make every participant a better engineer, we have been advised to use additional tools which examine the quality of the codebase we are working on. Moreover, they can help us to compare the project before and after GSoC. One of them is SonarQube. I have heard of it during my Bachelor but the focus while you are a student is more “let’s make it work” than “let’s think of code quality” :laughing:. Anyway, in this blog post, I will try to make a really quick tutorial how to install SonarQube. There exists official documentation (links provided below), but I will try to point out the steps I was confused about and I messed up a little bit :flushed:


Getting started

The first step is to download the sonarqube zip and extract it somewhere on your computer.

:heavy_exclamation_mark: The step that I forgot here was to create a DB scheme.

The installation guide is a little bit confusing especially if you start with “Getting started for two minutes” tutorial. So let’s not skip this step and create a scheme which our sonarQube server will use to store information for our projects. I also created a new user so that it can access only this scheme. Of course, you can use already existing user if you prefer.
The MySQL script looks like that:

# create the scheme
# default charset is UTF-8 - so no need to change it
# create new user with name sonarqube and password pass - DO NOT FORGET TO CHANGE THE PASSWORD
# The sonarqube account can be used only when connecting from the localhost
CREATE USER ‘sonarqube‘@‘localhost‘ IDENTIFIED BY ‘pass’;
# granting access only to sonarqube database
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON sonarqube.* TO ‘sonarqube‘@‘localhost‘;

After the DB and the user are successfully created. The next step is to update properties of sonarqube. Therefore, go to the folder where you extracted sonarqube. In the /conf folder, you will find file. This file contains properties of your sonarqube server. You have to set your DB properties:

# the username and the password you have created on the previous step

These three properties are mandatory and enough for a quick start. I have also updated sonar.web.port to 9999 because my wildfly server was running on the sonarqube’s default port 9000. But you can skip this step if you do not have anything running on this port.

:heavy_exclamation_mark: One thing to mention is that in the [sonarQubePath]/logs folder you can find the logs. If something is not running correctly, please examine these files. You have one for elastic search (es.log), one for your web server (web.log) and one for your sonarqube (sonar.log).

So now if you run this command and everything was set up successfully

[pathToSonarQube]/bin/[OS]/ console

your server will be available on the address http:\\localhost:9999 (or http:\\localhost:9000 if you haven’t changed the port). Congrats, your sonarqube server is installed and running :clap: :clap: :clap:

Although, we have installed sonarqube, to analyse a project, we need sonar scanner. Firstly, you download the zip and extract it to a folder somewhere on your computer. Then you have to update your [sonarScannerPath]/conf/ file. The only thing I have done was to uncomment property and change the port, so it looks like that:

:exclamation: If you are using the default sonarqube port, your address will be http://localhost:9000

Then you have to add your [sonarScannerPath]/bin folder to your path. It can be done easily by executing this command:

export PATH=$PATH:[sonarScannerPath]/bin

Be sure that you verify your installation by executing the command:

sonar-scanner -h

If it gives you unknown bash command then you haven’t added the [sonarScannerPath]/bin successfully to your path.

Take a breath, we are almost ready.

The final thing is to add file to the project which you want to analyse. A sample of a file looks like that:

# must be unique in a given SonarQube instance
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=Aerogear Unified Push Server

# Path is relative to the file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
# Encoding of the source code. Default is default system encoding

Finally, we are ready to run our sonar scanner. Go to the root folder of your project and execute this command:


:heavy_exclamation_mark: I had problems using only sonar-scanner command but the full path worked for me.

UHUUUU, now you can see the analysis report of your project. I am still exploring Aerogear Unified Push Server - the project I am working on during GSoC. Can’t wait to share its results :smiley:

Share your feedback and stay tuned for my next post.
Do not overthink, be happy and just keep smiling…


Get Started in Two Minutes
Installing the Server