Sonar plugin not working for projects that use ANT as a build script

Problem

I have just installed the Sonar Jenkins plugin. I went into my configured job (a free style job) that produces a WAR file artifact through an ANT build and did as follows:

  • Problems getting my ANT builds to work after OS upgrade
  • How to lookup the latest git commit hash from an ant build script
  • Jenkins unable to invoke ANT in MAC Slave
  • Attempting to run pre-commit git hook for checkstyle returns multiple “File not found!” errors
  • Echo a single line of an SvnAnt error message using Ant
  • Django error on makemessages “should be run from the Django Git tree or your project or app tree”
    1. Check the Sonar checkbox. (No problems here)

    2. Configure the install dir of sonar (No problems here)

    3. Checked the checkbox that states: “Check if this project is NOT built with maven 2″ (I am confused here)

      I have checked that box because I am not using maven for build, I am using ANT but it still asked me for required properties that resemble a lot MVN such as: Organization id, project id, project name, project version, source directories… etc..

      So I have filled those as well. When I click the play button “Build Now” the build seems to be running fine as it always had prior to sonar installation but it fails at the very end because its trying to execute MAVEN.

    See as follows:

    $ mvn -f /root/.jenkins/jobs/HRDA/workspace/pom.xml -e -B sonar:sonar
    FATAL: command execution failed
    java.io.IOException: Cannot run program “mvn” (in directory “/root/.jenkins/jobs/HRDA/workspace”): java.io.IOException: error=2, No such file or directory

    Questions

    1. Why is Sonar trying to execute Maven if I have checked the box that said check this box if you do NOT use Maven 2?

    2. Can I make use of this Sonar plugin if my apps are built with ANT, GANT, GRADLE?

    3. Do I have to reconvert my apps to use MVN builds?

    Thanks,
    – Dario

  • How to list the slowest JUnit tests in a multi-module Maven build
  • How to enable debug logging on jenkins?
  • Xcodebuild fails in jenkins with cocoapods
  • How can I programmatically obtain the hash of latest built Git revision of a Jenkins project?
  • Jenkins fails with github “git clone”
  • Modular Maven projects and multiple Git repositories
  • One Solution collect form web for “Sonar plugin not working for projects that use ANT as a build script”

    Like Oers suggested on my question comments if you are using ANT as a build script in your CI server (Jenkins in my case) you will have to use the SONAR-ANT-TASK to generate Sonar reports, do as follows:

    1. Download MySQL or any other Sonar supported RDBMS such as Postgres, Oracle, etc..’
    2. Download and Install sonar server.
    3. go to (sonar installation folder)/extras/database/mysql and run the create_database.sql script.
    4. I had to run an extra sql statement in my case using mysql, you can see here Unable to access Sonar MySQL database Caused by: java.sql.SQLException: Access denied for user 'sonar'@'glassfishdev.ccs.local' (using password: YES)
    5. Start Sonar by typing ./sonar.sh start
    6. Add the sonar ant task to your build script. You can follow this template http://docs.codehaus.org/display/SONAR/Analyse+with+Ant+Task+1.0
    7. DO NOT check the sonar check box in your Configure screen if you have the Hudson Sonar plugin for installed, as this plugin only works with Maven projects.
    8. Click the “Build Now” button. If everything above has been done correctly you should be able to see the reports at http://ipaddressofmachinesonarisinstalled:9000/

    Hope this helps,
    -Dario

    Git Baby is a git and github fan, let's start git clone.