- Ant 1.7.1 or higher
- Java 1.5 or higher
- Sonar 2.8 or higher. The server must be up while running the Ant task.
but without support of multi-modules
Older versions of Sonar are not supported.
- Download the Sonar Ant Task
Declare the Sonar Ant Task and define the configuration in a common Ant script file :
Define a new sonar Ant target in your Ant build script :
Execute the following command from the project base directory :
Analyse multi-modules project
Let's say that we have a project "Parent" containing two modules "Child1" and "Child2" and we want Sonar to be able to analyse the overall Parent multi-modules project :
The first thing to do is to declare all modules in the build.xml file of the Parent with the "sonar.modules" property :
Then, in each build.xml file of module, the Sonar key and Sonar source directories properties must be defined :
Of course additional but optional Sonar properties can also be defined in each module to provide for instance the binary directories, the list of libraries, ...
You can ask the Sonar task to execute an Ant target on the parent and for each module before collecting those property values. In that case, a new attribute "initTarget" must be added to the Sonar task definition in the build.xml file of the Parent :
Use Jacoco with Ant projects
Some additional configuration is required with Ant projects.
The Ant build.xml file must contain a dedicated target to launch either junit or testng unit tests. Let's take the following example with the target "test":
Then, in this example, the value of the parameter "sonar.jacoco.antTargets" must be set to "test". During Sonar analysis, the Sonar Jacoco plugin will take care to attach the Jacoco agent to the JVM and to launch the unit tests.
- Main sources and unit test sources can not be mixed in the same directory
Release 1.3 (2 issues)
|SONARPLUGINS-1432||Add the property sonar.verbose||Closed||Fixed|
|SONARPLUGINS-1567||Do not allow any more the use of the 'workDir' parameter in the sonar Ant task||Closed||Fixed|
Release 1.2 (2 issues)
|SONARPLUGINS-1395||Multi-module build fails, when Ant option "-buildfile" was specified and current directory isn't a project directory||Closed||Fixed|
|SONARPLUGINS-1194||Support for path-like structures in sonar.libraries values||Closed||Fixed|
Release 1.1 (3 issues)
|SONARPLUGINS-1641||CLONE - Provide ability to analyse Ant projects with several modules||Closed||Not A Bug|
|SONARPLUGINS-1110||Provide ability to analyse Ant projects with several modules||Closed||Fixed|
|SONARPLUGINS-1019||Support the attribute "baseDir"||Closed||Fixed|