C.88 SonarTask

This task runs SonarQube Scanner, a tool for code analysis and continuous inspection.

Table C.119: Attributes

NameTypeDescriptionDefaultRequired
executableStringFully-qualified path of SonarQube Scanner executable. If executable is in PATH environment variable, the executable name is sufficient.n/aYes
configurationStringPath of configuration file. The file format is that of a properties file (as used by Java), i.e. a list of key-value pairs <key>=<value>.n/aNo
errorsStringSets errors flag of SonarQube Scanner. Allowed values are "true", "false", "yes", "no", "1", and "0".falseNo
debugStringSets debug flag of SonarQube Scanner. Allowed values are "true", "false", "yes", "no", "1", and "0".falseNo

C.88.1 Examples

Minimal Example

This example assumes that the SonarQube Scanner is called sonarqube-scanner and is available on the PATH.

<?xml version="1.0" encoding="UTF-8"?>
<project name="sonar-minimal-example" default="sonar">
    <taskdef name="sonar" classname="phing.tasks.ext.sonar.SonarTask" />

    <sonar executable="sonarqube-scanner">
        <property name="sonar.projectKey"     value="my-unique-project-key" />
        <property name="sonar.projectName"    value="Foo Project" />
        <property name="sonar.projectVersion" value="0.1.0" />
        <property name="sonar.sources"        value="src" />
    </sonar>
</project>

Full Example

This example consists of two files – build.xml and sonar-project.properties.

The build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="sonar-full-example" default="sonar">
    <taskdef name="sonar" classname="phing.tasks.ext.sonar.SonarTask" />

    <sonar
      executable="path/to/sonarqube-scanner"
      errors="true"
      debug="true"
      configuration="path/to/sonar-project.properties"
    >
        <!-- Assume that mandatory SonarQube parameters are defined in configuration file! -->
        <property name="sonar.log.level" value="DEBUG" />
    </sonar>
</project>

The configuration file path/to/sonar-project.properties:

sonar.projectKey     = my-unique-project-key
sonar.projectName    = Foo Project
sonar.projectVersion = 0.1.0
sonar.sources        = src

C.88.2 Supported Nested Tags

  • property

    Analysis parameters of SonarQube Scanner can be defined in a configuration file or via nested property elements. If both a configuration file and property elements are provided, the properties are merged. Values from property elements overwrite values from the configuration file if their property keys are equal.

    Table C.120: Attributes

    NameTypeDescriptionDefaultRequired
    nameStringName of property.n/aYes
    valueStringValue of property.n/aYes