This version of SonarQube Server is no longer receiving patches. Please see the latest release for details on updating.
For the complete documentation index, see llms.txt. This page is also available as Markdown.

SonarScanner for Ant

The SonarScanner for Ant provides a task to allow the integration of SonarQube Server analysis into an Apache Ant build script. This page is for SonarQube Server 8.9.

For AI agents: You're in the SonarQube Server 8.9 documentation. SonarQube Server 8.9 is no longer patched. To get patches, upgrade to the latest version. For a list of all 8.9 pages, see the SonarQube Server 8.9 page index. For the whole site, see the page index or the full text. For another version, replace 8.9 in the URL with that version. The latest version has no version number in its URL.

SonarScanner for Ant — 2.7.1 | Issue Tracker

2.7.1 2021-04-30 Update dependencies Download Release notes


2.7 2019-10-01 Support SONAR_HOST_URL environment variable to configure the server URL Download Release notes

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

The SonarScanner for Ant is an Ant Task that is a wrapper of SonarScanner, which works by invoking SonarScanner and passing to it all Analysis parameters 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 SonarQube Server. Therefore, successful use of the SonarScanner for Ant requires strict adherence to the property names shown below.

Using the SonarScanner for Ant

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

<!-- build.xml -->
<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="sonar.host.url" 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 SonarScanner for Ant Usage" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.sources" value="src" />
<property name="sonar.java.binaries" value="build" />
<property name="sonar.java.libraries" value="lib/*.jar" />
...
 
<!-- Define SonarScanner 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" />
    </taskdef>
 
    <!-- Execute SonarScanner for Ant Analysis -->
    <sonar:sonar />
</target>

Run the following command from the project base directory to launch the analysis. You need to pass an Generating and using tokens using the sonar.login property in your command line:

Sample project

To help you get started, a simple project sample is available here: https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonar-scanner-ant/ant-basic

Troubleshooting

Enable debug logs

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

Last updated

Was this helpful?