3
votes

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:

  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

1
A guide to use sonar with ant is here: docs.codehaus.org/display/SONAR/Analyse+with+Ant+Task But I don't know how this works with jenkins - oers
Hi oers, I have followed those instructions ant it still seems to try to use maven. I get the following: [workspace] $ mvn -f /root/.jenkins/jobs/HRDA/workspace/pom.xml -e -B sonar:sonar -Dsonar.jdbc.driver=com.mysql.jdbc.Driver -Dsonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 ******** ******** -Dsonar.host.url=localhost:9000 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 - Viriato
the jenkins plugins seems to be maven based only. The maven 2 distinction may be there to make it compatible with maven 1. Maybe you could just run the ant task from jenkins? - oers
Thanks Oers, that did it. Unfortunately the configure screen was not that intuitive. - Viriato
you should post your steps as an answer (that you can accept later). For future users with the same problem :D - oers

1 Answers

3
votes

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