Skip to main content

Setup and run SonarQube on Mac

Published: 2020-08-31

It can be useful to run sonar locally. This doc explains how.

Sonar has 2 main parts: sonarqube, which is a server that displays scan results (among other things), and sonar-scanner, which does the actual scanning.

Note: This doc uses SonarQube version 8.4.2

# Prerequisites

  • Java version 8 or higher is installed
  • The directory ~/bin exists

# Install sonarqube

  1. Download sonarqube from
  2. Extract the zip file to ~/bin

# Install sonar-scanner

  1. Download sonar-scanner from
  2. Extract the zip file to ~/bin

# Bash helper functions

Add the following bash helper functions to your ~/.bash_profile then restart terminal


sonar_start() {

sonar_status() {
  ${SONARQUBE_PATH} status

sonar_stop() {

sonar_scan() {
  current_dir=$(basename $(pwd))
  echo "current_dir=${current_dir}"

  current_commit=$(git rev-parse --short HEAD)
  echo "current_commit=${current_commit}"

  # Optional: Include lombok
  lombok_jar_path=$(find ${HOME}/.gradle/caches -name lombok-1.18.10.jar)
  echo "lombok_jar_path=${lombok_jar_path}"

  echo ""

  -Dsonar.projectKey=${current_dir} \
  -Dsonar.projectName=${current_dir} \
  -Dsonar.projectVersion=${current_commit} \
  -Dsonar.source=. \ \
  # Optional: Include lombok${lombok_jar_path}

# Start sonarqube server

  1. Start server

  2. Check server status


# Run a scan with sonar-scanner

  1. Navigate to the repo that you want to run a scan on

  2. Run all unit tests so that sonar will report test coverage

  3. Run a scan


# View scan results

  1. Navigate to http://localhost:9000
  2. Click Projects

# Notes