Tuesday 1 May 2012

Analysing Ant Project with Jenkins and Sonar

Jenkins(or Hudson) and Sonar are perhaps two of the most mature open source tools available today for implementing continuous integration. They comes with a plethora of features that make life easier at monitoring and managing quality of multiple software development projects. Out of the box, Sonar is designed for Maven project. However, it can be configured to work with Ant projects. The following steps show you how to achieve this:

1. Download this plugin Sonar Ant Jar
2. Copy the jar file into <ANT_HOME>/lib

This is very important, otherwise your project would not compile properly.

Ant projects typically come with <PROJECT>.properties and <PROJECT>.xml files. So, just add the following code snippets into the existing ant build file. The code snippets assume that Sonar has already been installed to run at http://localhost:8080/sonar with Postgresql database. #Application Information
app.prettyName=My Project

# Sonar configuration

# For Linux
# ant.home=/usr/local/ant

# ForWindows

<project name="My Project - Build" default="compile" basedir=".">
     <!-- Define the properties file -->
     <property file=""/>

     <!-- Sonar database configuration -->
     <property name="sonar.jdbc.url" value="${sonar.db.url}" />
     <property name="sonar.jdbc.driverClassName" value="${sonar.db.driverClass}" />
     <property name="sonar.jdbc.username" value="${sonar.db.username}" />
     <property name="sonar.jdbc.password" value="${sonar.db.password}" />

     <!-- Sonar url -->
     <property name="" value="${sonar.web.url}" />

     <!-- Add the Sonar task -->
     <target name="sonar" depends="compile" description="Sonar static code analysis" >
         <taskdef name="sonar" classname="org.sonar.ant.SonarTask"
                       classpath="${ant.home}/lib/sonar-ant-task-1.3.jar" />
         <!-- list of mandatories Sonar properties -->
         <property name="sonar.sources" value="${src.home}" />

         <!-- list of optional Sonar properties -->
         <property name="sonar.projectName" value="${app.prettyName}" />
         <property name="sonar.binaries" value="${build.all}" />
         <property name="sonar.tests" value="${test.home}" />
             <path id="sonar.libraries">
                 <path refid="compile.classpath"/>
         <sonar key="${}" version="${app.version}" />

From the command prompt or inside your favourite IDE, run "ant -f myproject.xml sonar". This will take awhile depending on your project size. Once completed, myproject should show up on the project list inside Sonar.

Integrating with Jenkins/Hudson
Under "configure" panel, just add a new ant task to execute the "sonar" task.

1. For more details on Ant Task, see Analyse with Ant Task 
2. For more details on Jenkins, see Jenkins 
3. For more details on Sonar, see Sonar


  1. Hi I am using sonarqube-5.3,apache-ant-1.9.4 and Java 7 while I am running "ant -f myapp.xml sonar" I am ending up with below exception please help me out in resolving the issue..

    Caused by: <>\.sonar\batch\sonar-batch-shaded-5.3.jar|3659a1916b6b99eb1f6567db76884fcd
    (The filename, directory name, or volume label syntax is incorrect)

  2. Thanks to the author for the work done! I love when it is so clearly set out useful information
    Richard Brown virtual data room cost comparison

  3. The information shared was very much useful My sincere thanks for sharing this post Please continue to share this post
    Devops Training in Bangalore

  4. very well Explained Ant Project with
    installation, configuration and run also References Of jenkins/hudsons
    Thank you...
    Devops Training

  5. Best institute for 3d Animation and Multimedia Course training Classes

    Best institute for 3d Animation and Multimedia

    Best institute for 3d Animation Course training Classes in Noida- webtrackker Is providing the 3d Animation and Multimedia training in noida with 100% placement supports. for more call - 8802820025.

    3D Animation Training in Noida

    Company Address:

    Webtrackker Technology

    C- 67, Sector- 63, Noida

    Phone: 01204330760, 8802820025



  6. This comment has been removed by the author.

  7. I Got Job in my dream company with decent 12 Lacks Per Annum salary, I have learned this world most demanding course out there in the current IT Market from the big data training in bangalore Providers who helped me a lot to achieve my dreams comes true. Really worth trying Freelance seo expert in bangalore

  8. Thanks for sharing such a information. This is really too useful and have more ideas and keep sharing. I have read your article, it is very informative and usefull. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take data science training institute in btm layout.

  9. Thank you for sharing such valuable information.Good job.keep it up.Keep writing.
    machine learning institute in btm layout

  10. Such a great information for blogger iam a professional blogger thanks…

    Looking for Software Training in Bangalore , learn from Softgen Infotech Software Courses on online training and classroom training. Join today!


  11. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site. Real Time Experts Training in Bangalore center address bangalore

  12. Great Articles!!!informative contents...It shows your in-depth knowledge on the content...Thank you so much for sharing this pretty post...keep updating
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

  13. Keep share such valuable Content. Very helpful and knowledgeable, After Seeing this article it was awesome and very valuable.

    Tableau Online Training

  14. Communication is a two way process. If done properly, it gives excellent result. Thus opting for the best Integrated Marketing Communication Course on Talentedge is wise. To know more visit: