> For the complete documentation index, see [llms.txt](https://docs.sonarsource.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sonarsource.com/sonarqube-server/10.4/analyzing-source-code/scanners/sonarscanner-for-ant.md).

# SonarScanner for Ant

<details>

<summary>SonarScanner for Ant — 2.7.1 | <a href="https://sonarsource.atlassian.net/jira/software/c/projects/ANTTASK/issues">Issue Tracker</a></summary>

**2.7.1** <sup><sub>**2021-04-30**<sub></sup>\ <sup>Update dependencies</sup>\
[Download](https://binaries.sonarsource.com/Distribution/sonarqube-ant-task/sonarqube-ant-task-2.7.1.1951.jar)\
\
[Release notes](https://sonarsource.atlassian.net/issues/?jql=project+%3D+10136+AND+fixVersion+%3D+12372)

***

**2.7** <sup><sub>**2019-10-01**<sub></sup>\ <sup>Support SONAR\_HOST\_URL environment variable to configure the server URL</sup>\
[Download](https://binaries.sonarsource.com/Distribution/sonarqube-ant-task/sonarqube-ant-task-2.7.0.1612.jar)\
\
[Release notes](https://sonarsource.atlassian.net/issues/?jql=project+%3D+10136+AND+fixVersion+%3D+12371)

</details>

{% hint style="warning" %}
SonarScanner for Ant is deprecated. You can start using the SonarScanner instead by following the instructions below.
{% endhint %}

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 <a href="#moving-from-sonarscanner-for-ant-to-sonarscanner" id="moving-from-sonarscanner-for-ant-to-sonarscanner"></a>

The SonarScanner for Ant is an Ant Task that is a wrapper of the [SonarScanner CLI](/sonarqube-server/10.4/analyzing-source-code/scanners/sonarscanner.md), which works by invoking the SonarScanner CLI and passing to it all [Analysis parameters](/sonarqube-server/10.4/analyzing-source-code/analysis-parameters.md) 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 <a href="#prerequisites" id="prerequisites"></a>

The [SonarScanner CLI](/sonarqube-server/10.4/analyzing-source-code/scanners/sonarscanner.md) is installed on your machine.

### Configuring your sonar properties <a href="#configuring-your-sonar-properties" id="configuring-your-sonar-properties"></a>

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:

```css-79elbk
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](/sonarqube-server/10.4/analyzing-source-code/scanners/sonarscanner.md) for more information on how to configure project properties.

## Running the analysis <a href="#running-the-analysis" id="running-the-analysis"></a>

Create a [Generating and using tokens](/sonarqube-server/10.4/user-guide/user-account/generating-and-using-tokens.md) 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](/sonarqube-server/10.4/analyzing-source-code/scanners/sonarscanner.md) for more information.

### \[Archived] sample project <a href="#archived-sample-project" id="archived-sample-project"></a>

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>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sonarsource.com/sonarqube-server/10.4/analyzing-source-code/scanners/sonarscanner-for-ant.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
