Skip to end of metadata
Go to start of metadata
By SonarSource – GNU LGPL 3 – Issue TrackerSources
SonarQube Scanner for Ant – Compatible with SonarQube 6.7+ (LTS)

Table of Contents


The SonarQube Scanner for Ant provides a task to allow integration of SonarQube analysis into an Apache Ant build script.


The SonarQube Scanner for Ant version is compatible with SonarQube 6.7+.


  • SonarQube is already installed
  • At least the minimal version of Java supported by your SonarQube server is in use
  • The language plugins for each of the languages you wish to analyze are installed
  • You have read Analyzing Code Source
  • Ant 1.7.1 or higher


Just download the SonarQube Scanner for Ant on your machine.


The SonarQube Scanner for Ant is an Ant Task that is wrapper of SonarQube Scanner, which works by invoking SonarQube Scanner 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 Scanner for Ant 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.

Simple Project

Define a new sonar Ant target in your Ant build script:

<project name="My Project" default="all" basedir="." xmlns:sonar="antlib:org.sonar.ant">
<!-- Define the SonarQube global properties (the most usual way is to pass these properties via the command line) -->
<property name="" value="http://localhost:9000" />

<!-- Define the SonarQube project properties -->
<property name="sonar.projectKey" value="org.sonarqube:sonarqube-scanner-ant" />
<property name="sonar.projectName" value="Example of SonarQube Scanner for Ant Usage" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.sources" value="src" />
<property name="" value="build" />
<property name="" value="lib/*.jar" />

<!-- Define SonarQube Scanner for Ant Target -->
<target name="sonar">
	<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
		<!-- Update the following line, or put the "sonarqube-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
		<classpath path="path/to/sonar/ant/task/lib/sonarqube-ant-task-*.jar" />

	<!-- Execute SonarQube Scanner for Ant Analysis -->
	<sonar:sonar />

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

ant sonar


Any user who's granted Execute Analysis permission can run an analysis.

If the Anyone group is not granted Execute Analysis permission or if the SonarQube instance is secured (the sonar.forceAuthentication property is set to true), the analysis token of a user with Execute Analysis permission must be provided through the sonar.login property. Example: sonar-scanner -Dsonar.login=[my analysis token]

Sample Project

To help you get started, a simple project sample is available here:

Multi-Module Project

The configuration for parent and modules must be done in the parent build.xml file:

Parent build.xml
<!-- Set modules IDs -->
<property name="sonar.modules" value="module-one,module-two"/>
<!-- For modules, properties are inherited from the parent. They can be overridden as shown below: -->
<property name="module-one.sonar.projectName" value="Module One" />
<property name="module-one.sonar.sources" value="sources/java" />
<property name="module-one.sonar.binaries" value="target" />
<!-- Default module base directory is <curent_directory>/<module_ID>. It can be overridden if necessary -->
<property name="module-one.sonar.projectBaseDir" value="Module 1" />	

Enable Debug Logs

To enable debug logs, use regular Ant verbose option: -v 

ant sonar -v

Advanced Usage

Additional Analysis Parameters can be defined in the build.xml file or through command-line parameters.


  • No labels