Setup and run Sonar Analysis in Mac
Please download below software in a folder of choice
1.https://www.sonarqube.org/downloads/ == SonarQube Server
2.https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/ == Sonar-Scanner CLI
SonarQube is the central server holding the results of the analysis.
SonarQube Scanner is a tool to performs analysis and send the results to SonarQube.
Prerequisite to run sonar analysis: we need to have Java 8 on mac.
Best way to install java is through homebrew, which is a command line tool for MAC.
if homebrew is not installed, run the following command to install homebrew on mac
>>/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After homebrew is installed run following command to install java
>>brew cask install java
Two-Step Process to run the Quality analysis.
Step 1: Start the Sonar Qube server
In the first download (Sonar Qube Server), there is a bin folder, which contains three folders for three OS namely Mac, Windows, Linux.. Choose the MAC folder
Mac folder contains sonar.sh, utility file to interact with sonar server.
So our first step is to start the sonar server for this, we run this utility file by the opening terminal in (mac folder)it’s parent folder and execute the following command
`./sonar.sh start`
the list of available commands can be viewed using the following command
`./sonar.sh — help`
Step 2: running sonar-scanner cli to perform analysis
2.a: map sonar-scanner to point to sonar-qube server of choice (local in our case)
>for this open sonar-scanner.properties
and make sure it has following two lines uncommented
sonar.host.url=http://localhost:9000 # pointed to local sonar server running at port 9000
sonar.sourceEncoding=UTF-8
2.b: Now run the sonar-scanner cli using the following command in the project folder
>>sonar-scanner -Dsonar.projectKey=projectName -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000
the above command will run sonar analysis and upload the report to our local sonar server running at port 9000
understanding cli parameters
1. -Dsonar.projectKey = used to identify the project for report uploaded to the sonar server
2. -Dsonar.sources = for telling sonar-scanner which folder to use for running sonar analysis
3. -Dsonar.host.url = the location of our sonar server, (this is redundant in the current case since we have already written the property in sonar-scanner.properties above)