-->

Pages

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:

Installation
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.

Configuration
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.

myproject.properties #Application Information
app.name=myproject
app.version=1.0.0-RELEASE
app.prettyName=My Project
artifact.id=org.mycompany.myapp:myproject

# Sonar configuration
sonar.db.url=jdbc:postgresql://localhost:5432/sonar?charset=utf-8
sonar.db.driverClass=org.postgresql.Driver
sonar.db.username=username
sonar.db.password=password
sonar.web.url=http://localhost:8080/sonar

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

# ForWindows
ant.home=C:/apps/ant


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

     <!-- 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="sonar.host.url" 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"/>
             </path>    
         <sonar key="${artifact.id}" version="${app.version}" />
    </target>
</project

Running
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.

Reference: 
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

26 comments:

  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: java.io.FileNotFoundException: <>\.sonar\batch\sonar-batch-shaded-5.3.jar|3659a1916b6b99eb1f6567db76884fcd
    (The filename, directory name, or volume label syntax is incorrect)

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
    Replies
    1. I am technology Enthusiast. Your blog is really awesome, attractive and impressive. I like the way you think. it is very useful for Java SE & Java EE Learners. Your article adds best knowledge to our Java Online Training in India. or learn thru Java Online Training in India Students. or learn thru JavaScript Online Training in India. Appreciating the persistence you put into your blog and detailed information you provide. Kindly keep blogging.

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

    ReplyDelete
  5. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    Best AWS training in bangalore

    ReplyDelete
  6. 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

    Email: info@webtrackker.com

    Website: http://webtrackker.com/Best-institute-3dAnimation-Multimedia-Course-training-Classes-in-Noida.php

    ReplyDelete
  7. Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

    DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.

    Good to learn about DevOps at this time.


    devops training in chennai | devops training in chennai with placement | devops training in chennai omr | devops training in velachery | devops training in chennai tambaram | devops institutes in chennai | devops certification in chennai | trending technologies list 2018

    ReplyDelete
  8. Read all the information that i've given in above article. It'll give u the whole idea about it.
    Best Devops online Training
    Online DevOps Certification Course - Gangboard

    ReplyDelete
  9. Sap fico training institute in Noida

    Sap fico training institute in Noida - Webtrackker Technology is IT Company which is providing the web designing, development, mobile application, and sap installation, digital marketing service in Noida, India and out of India. Webtrackker is also providing the sap fico training in Noida with working trainers.


    WEBTRACKKER TECHNOLOGY (P) LTD.
    C - 67, sector- 63, Noida, India.
    F -1 Sector 3 (Near Sector 16 metro station) Noida, India.

    +91 - 8802820025
    0120-433-0760
    0120-4204716
    EMAIL: info@webtrackker.com
    Website: www.webtrackker.com

    ReplyDelete
  10. It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.

    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training
    Selenium training in bangalore

    ReplyDelete
  11. I simply want to give you a huge thumbs up for the great info you have got here on this post.
    online Python training
    python training in chennai

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete

  13. Just seen your Article, it amazed me and surpised me with god thoughts that eveyone will benefit from it. It is really a very informative post for all those budding entreprenuers planning to take advantage of post for business expansions. You always share such a wonderful articlewhich helps us to gain knowledge .Thanks for sharing such a wonderful article, It will be deinitely helpful and fruitful article.
    Thanks
    DedicatedHosting4u.com


    ReplyDelete
  14. I am overwhelmed by your post with such a nice topic. Usually, I visit your blogs and get updated with the information you include but today’s blog would be the most appreciable...

    Thanks
    Cpa offers

    ReplyDelete

  15. Your post is very good. I got to learn a lot from your post. Thank you for sharing your article for us. it is amazing post
    what is seo
    types of seo

    ReplyDelete
  16. This is a fantastic idea! I like it a lot because it's super easy for the audience to see the value of opting in. wonderful and amazing post very use full your post thanks for sharing your article
    Android Application development
    Web application

    ReplyDelete
  17. 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

    ReplyDelete
  18. Ant controlTo get rid of ants, it is important to identify the ant species before attempting ant control. Some ant species, like Pharaoh ants, can be controlled using baits, while others cannot. To get rid of ants successfully, it is usually necessary to follow them back to their colony and treat the colony directly. Terminix® pest control professionals have the experience to correctly identify your ants and kill them. ants removal service

    ReplyDelete
  19. 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.

    ReplyDelete