This version of the SonarQube documentation is no longer maintained. It relates to a version of SonarQube that is not active.

See latest version
Start Free
10.0 | Analyzing source code | Scanners | SonarScanner for Ant

SonarScanner for Ant

On this page

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, which works by invoking the SonarScanner and passing to it all properties named following a sonar.* convention. It is now deprecated. We recommend using the SonarScanner 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 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 for more information on how to configure project properties.

Running the analysis

Create a Sonar token 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 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


Was this page helpful?

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARLINT, SONARQUBE, SONARCLOUD, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License