SonarQube Scanner Setup

1. Get SonarQube Scanner

1.1 Visit SonarQube official site for the latest version; if you are using SonarQube 5.5 or earlier, visit the archived runner page to get runner-2.4 (notice that sonar-runner is the previous version of sonar-scanner)

1.2 Download the required version for Windows to your Downloads folder

2. Extracts to C:\sonarqube

2.1 Extracts the downloaded file to C:\sonarqube\scanner-3.x using your preferred unzip program

3. Define system variables

3.1 Open system properties dialog

3.2 Select Advanced System Settings

3.3 Click on Environment Variables... button

3.4 On the Envirnoment Variable dialog, click on system variables New... button

3.5 Define the SONAR_SCANNER_HOME variable

3.6 Accept changes and edit the system variable Path to add ;%SONAR_SCANNER_HOME%\bin at the end

3.7 Accept changes and close all dialogs

3.8 Depending on you Windows version, you need to restart to apply the changes

4. Setup SonarQube Scanner properties

4.1 Configure your database driver and the username/password to connect to database

%SONAR_SCANNER_HOME%\conf\sonar-scanner.properties
#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here

#----- Default SonarQube server
#sonar.host.url=http://localhost:9000
sonar.core.serverBaseURL=http://localhost:9000

#----- PostgreSQL
sonar.jdbc.url=jdbc:postgresql://localhost/sonar

#----- MySQL
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8

#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE

#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor

#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=<database-password>

#----- Default source code encoding
#sonar.sourceEncoding=UTF-8

#----- Security (when 'sonar.forceAuthentication' is set to 'true')
#sonar.login=admin
#sonar.password=admin

5. Quick check

5.1 A quick sonar-scanner check

> sonar-scanner --version
C:\sonarqube\scanner-3.x
SonarQube Scanner 3.0.3.778
Java 1.8.0_111 Oracle Corporation (64-bit)
Windows NT (unknown) 10.0 amd64

1. Get SonarQube Scanner

1.1 Visit SonarQube official site for the latest version; if you are using SonarQube 5.5 or earlier, visit the archived runner page to get runner-2.4 (notice that sonar-runner is the previous version of sonar-scanner)

1.2 Download the latest version via wget command to /tmp folder

$ wget -P /tmp https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.0.3.778-linux.zip

2. Extracts to /opt/sonarqube/

2.1 Extracts the downloaded file to /opt/sonarqube

$ sudo unzip /tmp/sonar-scanner-cli-3.0.3.778-linux.zip -d /opt/sonarqube

$ ls -la /opt/sonarqube/sonar-scanner-3.0.3.778-linux
total 24
drwxr-xr-x 6 root  root  4096 May 12 12:49 .
drwxr-xr-x 6 sonar sonar 4096 Aug 25 17:07 ..
drwxr-xr-x 2 root  root  4096 May 12 12:49 bin
drwxr-xr-x 2 root  root  4096 Aug 25 15:28 conf
drwxr-xr-x 4 root  root  4096 Aug 25 15:28 jre
drwxr-xr-x 2 root  root  4096 Aug 25 15:28 lib

3. Define a symbolic link to SonarQube Scanner

3.1 For easy upgrades on future it is highly recommended to create the symbolic link

$ sudo ln -s /opt/sonarqube/sonar-scanner-3.0.3.778-linux /opt/sonarqube/sonar-scanner

4. Setup SonarQube Scanner properties

4.1 Configure your database driver and the username/password to connect to database

/opt/sonarqube/sonar-scanner/conf/sonar-scanner.properties
#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here

#----- Default SonarQube server
#sonar.host.url=http://localhost:9000
sonar.core.serverBaseURL=http://localhost:9000

#----- PostgreSQL
sonar.jdbc.url=jdbc:postgresql://localhost/sonar

#----- MySQL
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8

#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE

#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor

#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=<database-password>

#----- Default source code encoding
#sonar.sourceEncoding=UTF-8

#----- Security (when 'sonar.forceAuthentication' is set to 'true')
#sonar.login=admin
#sonar.password=admin

5. Add SonarQube Scanner to PATH

5.1 If you want to execute SonarQube Scanner from command line, it is recommended to add to your PATH

~/.profile
JAVA_HOME=/opt/java/default-jdk/
export JAVA_HOME
SONAR_SCANNER_HOME=/opt/sonarqube/sonar-scanner
export SONAR_SCANNER_HOME
PATH="$JAVA_HOME/bin:$SONAR_SCANNER_HOME/bin:$PATH"
export PATH