This page describes how to integrate SonarQube into a build script for Apache Ant.
The Ant task is a thin wrapper around the SonarQube Runner, which works by invoking the runner and passing to it all properties named following a sonar.* convention. This has the downside of not being very Ant-y, but the upside of providing instant availability of any new analysis parameter introduced by a new version of a plugin or of SonarQube itself. Therefore, successful use of the SonarQube Ant task requires strict adherence to the property names shown below.
You may also consult the list of analysis parameters for additional properties which will be honored in an Ant-based analysis.
Define a new
sonar Ant target in your Ant build script:
Run the following command from the project base directory to launch the analysis:
Since SonarQube 3.4, if a project cannot be accessed anonymously, the
sonar.password properties are required to run an analysis on this project. These properties have to be set to the credentials of a user having the User role on this project. You can set them either:
- directly on the command line by adding
- or in the build.xml file
A project cannot be anonymously accessed when either:
The configuration for parent and modules must be done in the parent build.xml file:
- Modules with the same structure: projects/multi-module/ant/java-ant-modules-same-structure
- Modules with different structures: projects/multi-module/ant/java-ant-modules-different-structures
Multi-module and Multi-language Project
Since SonarQube 3.3, it is possible to run an analysis on a multi-module project whose modules contains source code from different languages.
In addition to the multi-module configuration, the only mandatory property to set is the language for each module:
Additional analysis parameters can be defined in the build.xml file or through command-line parameters.
Migrating from SonarQube Ant Task 1.X to SonarQubeAnt Task 2.0
The SonarQubeAnt Task 2.0 can run analyses from configuration files designed for SonarQube Ant Task 1.X.
This compatibility mode is automatically activated. But we highly recommend you to migrate to the new format as this compatibility mode will be dropped sooner or later in the next versions.