The SonarQube Runner is recommended as the default launcher to analyze a project with SonarQube.

Prerequisites

You must have previously installed the SonarQube Runner and read Analyzing Code Source.

Usage

Simple Project

Create a configuration file in the root directory of the project: sonar-project.properties

# Required metadata
sonar.projectKey=my:project
sonar.projectName=My project
sonar.projectVersion=1.0

# Path to the parent source code directory.
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional. If not set, SonarQube starts looking for source code
# from the directory containing the sonar-project.properties file.
sonar.sources=src

# Encoding of the source code
sonar.sourceEncoding=UTF-8

# Additional parameters
sonar.my.property=value

Run the following command from the project base directory to launch the analysis:

sonar-runner

Project Samples

To help you get started, simple project samples are available for most languages on github. They can be browsed or downloaded. You'll find them filed under projects/languages.

Multi-language Project

Since SonarQube 4.2, it is possible to run an analysis on a multi-language project. To do so, the sonar.language property just has to be removed. Conversely, if for some reason you want to perform a single language-only analysis, make sure sonar.language is specified.

To help you get started, a multi-language project sample can be browsed or downloaded from github: projects/languages/multi-language/multi-language-java-javascript-sonar-runner

Multi-module Project

There are two ways to define a multi-module structure in SonarQube:

 Using the given file structure...... with the given 'properties' files

Way #1

Set all the configuration in the properties file in the root folder

# Root project information
sonar.projectKey=org.mycompany.myproject
sonar.projectName=My Project
sonar.projectVersion=1.0-SNAPSHOT

# Some properties that will be inherited by the modules
sonar.sources=src

# List of the module identifiers
sonar.modules=module1,module2

# Properties can obviously be overriden for
# each module - just prefix them with the module ID
module1.sonar.projectName=Module 1
module2.sonar.projectName=Module 2

Way #2

Set the configuration in multiple properties files

# Root project information
sonar.projectKey=org.mycompany.myproject
sonar.projectName=My Project
sonar.projectVersion=1.0-SNAPSHOT

# Some properties that will be inherited by the modules
sonar.sources=src

# List of the module identifiers
sonar.modules=module1,module2
# Redefine properties
# Note that you do not need to prefix the property here
sonar.projectName=Module 1
# Redefine properties
# Note that you do not need to prefix the property here
sonar.projectName=Module 2

 

Noteworthy:

To help you get started, multi-module project samples can be browsed or downloaded from github:

Running Other Tasks

# To run the computation of views (Views plugin is required)
sonar-runner views

# To run the computation of reports (Report plugin is required)
sonar-runner report

# To run the computation of developer data (Developer Cockpit plugin is required)
sonar-runner devcockpit

Advanced Usage

If a sonar-project.properties file cannot be created in the root directory of the project, there are several alternatives:

The root folder of the project to analyze can be set through the sonar.projectBaseDir property since SonarQube Runner 2.4 (was previously project.home). This folder must contain a sonar-project.properties file if the mandatory properties (like sonar.projectKey) are not specified on the command line.

Additional analysis parameters can be defined in this project configuration file or through command-line parameters. 

Troubleshooting

If you get a Java heap space error or java.lang.OutOfMemoryError, you can increase the memory via the SONAR_RUNNER_OPTS environment variable:

export SONAR_RUNNER_OPTS="-Xmx512m -XX:MaxPermSize=128m"

On Windows environments, avoid the double-quotes, since they get misinterpreted and combine the two parameters into a single one.

set SONAR_RUNNER_OPTS=-Xmx512m -XX:MaxPermSize=128m