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 analysis into an Apache Ant build script. This page is for SonarQube 10.3.

For AI agents: You're in the SonarQube Server 10.3 documentation. For a list of all 10.3 pages, see the SonarQube Server 10.3 page index. For the whole site, see the page index or the full text. For another version, replace 10.3 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 analysis into an Apache Ant build script.

Moving from SonarScanner for Ant to SonarScanner

The SonarScanner for Ant is an Ant Task that is a wrapper of the SonarScanner CLI, which works by invoking the SonarScanner CLI and passing to it all Analysis parameters named following a sonar.* convention. It is now deprecated. We recommend using the SonarScanner CLI directly.

If you’re still using the SonarScanner for Ant, follow these steps to remove the wrapper from your build file, create a sonar-project.properties in your project, and run the analysis.

Prerequisites

The SonarScanner CLI is installed on your machine.

Configuring your sonar properties

  1. Create a sonar-project.properties in your project.

  2. Move the sonar.* properties from your build.xml file to the sonar-project.properties file. For example:

sonar.host.url="sonarHostUrl"
sonar.projectKey="projectKey"
sonar.projectName="projectName"
sonar.projectVersion="1.0"
sonar.sources="src"
sonar.java.binaries="build" 
sonar.java.libraries="lib/*.jar"

See SonarScanner CLI for more information on how to configure project properties.

Running the analysis

Create a Generating and using tokens and run the analysis using sonar-scanner -Dsonar.token=myAuthenticationToken.

Alternatively, instead of passing the token in your command line, you can create the SONAR_TOKEN environment variable and set the token as its value before you launch the analysis.

See SonarScanner CLI for more information.

[Archived] sample project

For comparison purposes, a sample SonarScanner for Ant project is available here: https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonar-scanner-ant/ant-basic

Last updated

Was this helpful?