SonarCloud | Advanced setup | CI-based analysis | SonarScanner for Ant

On this page

SonarScanner for Ant

The SonarScanner for Ant provides a task that is a wrapper of SonarScanner to allow integration of SonarCloud analysis into an Apache Ant build script. It is now deprecated and will be removed in the future. We recommend adjusting your configuration to use the SonarScanner CLI directly.

Moving from SonarScanner for Ant to SonarScanner CLI

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

Prerequisites

The SonarScanner CLI is installed on your machine. See Installation for more details.

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="https://sonarcloud.io"
sonar.organization="sonarOrganization"
sonar.projectKey="projectKey"
sonar.projectName="Example of SonarScanner for Ant Usage"
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

1. Set the environment variable SONAR_TOKEN with the personal access token generated on My account > Security > Generate Tokens. Note that the token can also be set through the command line argument -Dsonar.token.

2. Run the command sonar-scanner , or sonar-scanner.bat  on Windows, from the project base directory to run the analysis.

[Archived] sample project

For comparison purposes, a sample SonarScanner for Ant project is available here.

© 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