SonarQube is an open platform for managing continuous inspection of the code quality, which can locate potential errors in the codebase. It currently supports more than 20+ programming languages which include support on  C#, JavaScript, C/C++, TypeScript, Go, Python, etc., and other languages. In this article, we will see How to Setup SonarQube locally on Mac OS with HomeBrew

Installation steps

The installation of SonarQube is divided into these steps:

  1. Install java environment
  2. Installation of SonarQube/Sonar-Scanner
  3. Set SonarQube environment Variable
  4. Start SonarQube
  5. Log in to SonarQube Dasboard
  6. Create a new project in SonarQube Dashboard
  7. Add sonar-project. properties
  8. Run Analysis
  9. View SonarQube scan results

Install Java Environment 

Follow this article’s first section to install and configure java in MacOs.

Installation of SonarQube/Sonar-Scanner

brew install sonar
brew install sonar-scanner

Set SonarQube environment Variable

Enter vim ~/.bash_profile in the terminal to configure the sonar path. {version } can be replaced with the installed current version.

export SONAR_HOME=/usr/local/Cellar/sonar-scanner/{version}/libexec 

Start SonarQube

brew services start sonarqube

Log in to SonarQube Dasboard

Enter http://localhost:9000 in the browser to enter the following page. 

Log in to SonarQube and enter the account and password admin/admin

Create new project in SonarQube Dashboard

  1. Click -> Create new project button.

    SonarQube Create Project Key

  2. Provide -> Project key and a Display name and click the Set Up button.

  3. Under Provide a token, select Generate a token. Give your token a name, click the Generate button, and click Continue.

  4. Select your project’s main language under Run analysis on your project, and Operating System. Download Sonar Scacommands to execute a Scanner on your code.

    SonarQube Generate token

Add sonar-project Properties

Add a sonar-project. properties file in your project directory

# unique project identifier (required)
# project metadata (used to be required, optional since SonarQube 6.1)
# path to source directories (required)
# path to test source directories (optional)

Run Analysis

Switch to the project path and execute sonar-scanner

sonar-scanner \
 -Dsonar.projectKey=SalesProject \
 -Dsonar.sources=. \ http://localhost:9000 \

View SonarQube scan results

Log in to SonarQube to view scan results

SonarQube Scan results
SonarQube Scan results

Udemy Offers 2021