Installation SonarScanner

Author
By Darío Rivera
Posted On in Static Code Analysis

We have already talked in several articles about SonarQube, its installation, starting as a service in Linux and in MacOS, among other aspects. Today we will see the client-side component, Sonar Scanner. This software package allows us to run static code analysis on our machines and then upload it to the server where SonarQube is installed and be able to analyze that report. Let's see how to configure this client.

Installation

As you know, SonarQube has a free cloud service for open source code projects called SonarCloud. If you are using SonarCloud or plan to use it, you should refer to the following documentation where you can download the client:

https://sonarcloud.io/documentation/analysis/scan/sonarscanner/

If, on the other hand, your project is private and you have installed SonarQube on a dedicated server, you should refer to the following documentation to download the client:

https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/

In either case, you should select the appropriate option for your operating system and architecture. As of the writing of this post, SonarScanner is in version 4.1 for the cloud and 4.4 for standalone installations.

Once you have downloaded the Sonar Scanner package, the next step will be to unzip it and place it in a location of your choice. In MacOS, a good location could be /usr/local/var/sonar-scanner-4.x while in Windows it could be C:\sonar-scanner-4.x. After that, you will need to add the location of the binaries to the system path variable, which is usually quite easy in MacOS, where you can add it to the /etc/paths file, while in Windows you will need to access the environment variables configuration and add it there.

To test that everything has gone well so far, you should be able to run the following command in the console and get a result similar to the following.

fermius@computer:~# sonar-scanner -h
INFO:
INFO: usage: sonar-scanner [options]
INFO:
INFO: Options:
INFO:  -D,--define      Define property
INFO:  -h,--help             Display help information
INFO:  -v,--version          Display version information
INFO:  -X,--debug            Produce execution debug output

Configuration

At this point there are two ways to configure your project based on whether you are using the cloud or standalone version of SonarQube. I invite you to continue browsing according to your preference.

- Configuration in SonarCloud
- Configuration in Standalone SonarQube


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.