The SonarQube Runner is recommended as the default launcher to analyze a project with SonarQube.
You must have previously installed the SonarQube Runner and read Analyzing Code Source. You must also have the language plugins installed for each of the languages you wish analyzed in your projects.
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 sonar.modules is set. # 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:
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.
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.
There are two ways to define a multi-module structure in SonarQube:
|Using the given file structure...||... with the given 'properties' files|
Set all the configuration in the properties file in the root folder
Set the configuration in multiple properties files
the folder of a module contains white spaces or special characters:
module1.sonar.projectBaseDir=My Module One
the module is not located directly in the parent folder, but in a deeper directory structure:
To help you get started, multi-module project samples can be browsed or downloaded from github:
# 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
If a sonar-project.properties file cannot be created in the root directory of the project, there are several alternatives:
The properties can be specified directly through the command line. Ex:
sonar-runner -Dsonar.projectKey=myproject -Dsonar.sources=src1
project.settings can be used to specify the path to the project configuration file (this option is incompatible with the
sonar.projectBaseDir properties). Ex:
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.
If the files to be analyzed are not in the directory where the analysis starts from, use the
projectBaseDir property to move analysis to a different directory. E.G. analysis begins from jenkins/jobs/myjob/workspace but the files to be analyzed are in ftpdrop/cobol/project1.
sonar.project.BaseDir=/home/ftpdrop/cobol/project1 sonar.sources=src sonar.cobol.copy.directories=/copy
For more, see the listing of analysis parameters.
If you get a Java heap space error or java.lang.OutOfMemoryError, you can increase the memory via the SONAR_RUNNER_OPTS environment variable:
On Windows environments, avoid the double-quotes, since they get misinterpreted and combine the two parameters into a single one.