Advanced Maven parameters
There are extra parameters that can be used when running the Sonar maven plugin.
Hide sources
Sometimes, for security or other reasons, project sources must not be published.
option |
sonar.importSources |
usage |
|
from pom.xml |
|
version |
since 1.5 |
Inject historical data
When using Sonar, it becomes quickly necessary to input historical data and to highlight some events. It is possible by going for example in a tag and use the sonar.projectDate option. By default, the version name to be used is the one in the pom.xml, but it is possible to override it using the sonar.projectVersion option.
option |
sonar.projectDate & sonar.projectVersion |
usage |
|
from pom.xml |
N/A |
version |
since 1.5 |
Exclude resources
The resources (classes/packages) to exclude from analysis are configured online in the project settings page. This configuration can also be set maven-side :
option |
sonar.exclusions |
value |
comma-separated list of wildcard patterns. Example : com/mycompany/**/*.java,**/*Dummy.java |
from pom.xml |
|
version |
since 1.8 |
Exclude modules
Some project modules should not be analyzed and consolidated with global project measures, for instance samples, integration tests or generated code.
If a module's artifactId differs from its module name (the directory name) : it is the artifactId that should be use instead of the module name.
option |
sonar.skippedModules |
usage |
|
from pom.xml |
N/A |
since version |
1.5 |
Include modules
List the full list of modules to analyse, all others modules are automatically ignored. Be careful : the root project must be added to the list.
If a module's artifactId differs from its module name (the directory name) : it is the artifactId that should be use instead of the module name.
option |
sonar.includedModules |
usage |
|
from pom.xml |
N/A |
since version |
2.2 |
Manage SCM branches
It is possible to run the Sonar maven plugin on a branch.
option |
sonar.branch |
usage |
|
from pom.xml |
|
since version |
branch since 1.3, sonar.branch since 1.10 |
Define the quality profile to be used
Through the Sonar web interface, you can define as many quality profiles as you want and you can easily associate one of this quality profile to a given project. You can also make this association by using the property "sonar.profile". The value of this property overload any configuration made in the Sonar web interface.
option |
sonar.profile |
usage |
|
from pom.xml |
|
version |
since 1.6 |
Dynamic analysis
Dynamic analysis relates to unit tests execution. By default, those unit tests are executed but you can optionally decide to do only static analysis or to reuse existing unit tests reports.
option |
sonar.dynamicAnalysis |
values |
|
usage |
|
from pom.xml |
|
version |
since 1.7 |
option |
sonar.surefire.reportsPath |
values |
the absolute or relative path of the surfire reports directory |
usage |
|
from pom.xml |
|
version |
since 1.7 |
option |
sonar.cobertura.reportPath |
values |
the absolute or relative path of the cobertura xml report file |
usage |
|
from pom.xml |
|
version |
since 1.7 |
option |
sonar.clover.reportPath |
values |
the absolute or relative path of the clover xml report file |
usage |
|
from pom.xml |
|
version |
since 1.7 |
Run maven phase or goal prior to analysis
When Sonar need a phase or maven goal to be executed prior to analysis, this parameter can be used. A good example is generate-sources.
option |
sonar.phase |
usage |
|
from pom.xml |
<sonar.phase>generate-sources</sonar.phase> |
version |
since 1.10 |
Reuse existing configuration
Enables to pass definition of quality profiles to Sonar to run analysis.
option |
sonar.reuseExistingRulesConfiguration |
version |
since 1.11. Deprecated in 2.3. Removed in 2.5 |
This option was removed as it is highly unstable.
Reuse findbugs reports
Enables to reuse Findbugs report that has already been generated.
option |
sonar.findbugs.reportPath |
version |
since 2.3 |
Increasing HTTP timeouts of requests to Sonar server
The Maven plugin executes some HTTP requests to the Sonar server. Two timeouts makes the call fail if the server connection is too slow. In such a case the timeouts can be increased from Maven properties.
options |
sonar.host.connectTimeoutMs and sonar.host.readTimeoutMs |
default values |
respectively 30'000 and 60'000 milliseconds |
version |
since 1.12 |
Deactivating bytecode analysis
Since Sonar 2.0, the java bytecode is analyzed by Sonar in order to extract dependencies between packages and files. Those dependencies are used for instance to display the DSM (Dependency System Matrix). This bytecode analysis can be deactivated.
option |
sonar.skipDesign |
usage |
|
from pom.xml |
|
version |
since 2.O |
Using environment variables
It is possible since v 1.5 to use environment variables in the sonar.properties file.
To use an environment variable, use the following syntax : ${env:NAME_OF_ENV_VARIABLE}.
For example :
Setting absolute path for rule extensions
It is possible to define an absolute path for rule extensions in the sonar.properties file. This parameter is useful when Sonar is deployed as a WAR. It avoids from packaging the WAR file each time rule extensions JARs are updated. The directory must contains subdirectories like checkstyle/ and pmd/
Example
version |
before 2.2 |
Specifying the language of the source code
By default, Sonar is using Java source code analysers. If a Sonar plugin allows to analyse another given language, the associated source code analysers can be activated with the property 'sonar.language'.
option |
sonar.language |
usage |
|
from pom.xml |
|
version |
since 2.0 |
Configure minimum period for purges
Sonar has an embedded purge mechanism which is fairly powerful to avoid keeping useless data. This mechanism is using a minimum period during which a resource created should not be suppressed whatever its state. This is set by default to 12 hours and should not be changed. The only situation you could want to change this is in case a projects takes more than 12 hours to be analyzed by Sonar.
option |
sonar.purge.minimumPeriodInHours |
usage |
in batch configuration (pom, environment variable, system property) or in properties table |
default value |
12 hours |
version |
since 2.4 |

