SonarScanner for Ant
SonarScanner for Ant is deprecated. You can use the SonarScanner CLI instead by following the instructions below.
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
- Create a
sonar-project.properties
in your project. - Move the
sonar.*
properties from yourbuild.xml
file to thesonar-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.binarie="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.