Tuesday, November 24, 2009

Hudson + Sonar = A Perfect Match!

Last week, I blogged about "Continuous Quality Using Sonar". It requires just 5 simple steps if you have Hudson running as your CI(Continuous Integration) server to install and use Sonar. Yes, 5 simple steps is all you need to get a neat and intuitive dashboard from Sonar. So, lets see what those 5 simple steps are.

Step 1: Download, install and start the Sonar Server. 
Download the latest Sonar release from here. Unzip the distribution to your favorite location, mine was in C:\dev\projects\sonar-1.11.1. Based on your platform, run the batch file or the shell script from within the bin folder. On windows, it is C:\dev\projects\sonar-1.11.1\bin\windows-x86-32\StartSonar.bat.
Open a web browser and browse to http://localhost:9000. The default login and password is admin/admin.

Step 2: Install and Configure Sonar plugin on Hudson.
Open your Hudson dashboard. Mine is located at http://localhost:7223. Click on Manage Hudson - Manage Plugins. Click now on the Available tab, you should see the Hudson Sonar Plugin. Check this plugin and click on the Install button at the far right hand corner.
Restart Hudson and you should be able to see the plugin in the Installed tab as shown below:




Next, configure the Sonar plugin from within Manage Hudson -> Configure System. I am using the default database, and so didn't make any changes here. However, if you are using a different database server, you need to provide the database URL, username, password and so on as shown below.




Step 3: Configure your Hudson Job 
In order to activate Sonar on a project, click on Configure, and within the Post-build Actions, check Sonar and you should see the following properties. Fill those properties and Save this configuration.




Step 4: Build your project
Even though you don't require Maven to be used as a build tool for your project, Sonar does still require Maven to run. If Maven isn't installed, you can download and install Maven from here.
Force a build on your Job on the Hudson dashboard. If Maven is installed, you should be able to see the following output in the Console Output on Hudson dashboard.




Step 5: Browse to Sonar Dashboard
Once the build succeeds in the last step, browse to http://localhost:9000. And you should be able to see the Sonar Dashboard as such:


That's all it is to download, install, configure and get continuous quality updates from Hudson and Sonar. The above steps took me less than 15 minutes.

I am sure many of you are already using Sonar. I haven't used it with any of my clients yet. Hopefully, will do so soon. Share your thoughts if you are using Sonar.

P.S: In case you are using other CI servers, no need to panic. You can read a detailed documentation here for all the CI servers Sonar supports here.

55 comments:

  1. It's been a while haven't see news from you, welcome back :P

    ReplyDelete
  2. Yes indeed. It was a long time. Thanks so much.

    ReplyDelete
  3. Your blog is great! Keep up the good work! :-)

    Do you know if Sonar works with Groovy code?

    ReplyDelete
  4. As long as you are using Maven for building your project it shouldn't matter what Language you are using.

    On the other hand, if you're using Hudson or any other CI server, Sonar should work.

    ReplyDelete
  5. Great tutorial Meera! It's nice to see you back. Please keep them coming.

    Cheers, L.

    ReplyDelete
  6. Hi
    We are using RAD for development & Tomcat5.5 Appserver and SVN as repository. I have installed Hudson & Sonar. Followed the steps mentioned. But having trouble configuring maven. Could you please share some useful URL's for ref. Thanks. Harsha

    ReplyDelete
  7. I am not able to install sonar lug in from Hudson. Can you explain me on this.

    ReplyDelete
  8. Sangeetha,
    I need more information to figure out what's wrong. Any error?

    ReplyDelete
  9. Harsha,
    I used Ant, haven't tried anything with Maven yet.

    ReplyDelete
  10. Hi Meera,

    I have installed hudson and my builds are successful. When I try to install sonar plug in to the Hudson. I am getting connection timed out error.
    "java.net.ConnectException: Connection timed out: connect"
    I am using the same sonar-1.11.1 .
    I tried making all proxy settings corresponding to my account. internet works fine, out of the box but the problem persist while installing sonar alone. Can you pls explain on this.

    ReplyDelete
  11. Hi Meera,
    Thanks for this blog, its highly helpful.

    In hudson My builds are successful, I am facing problem only during sonar build.
    The following is error:

    [INFO] Trace
    org.apache.maven.lifecycle.LifecycleExecutionException: Unable to build project for plugin 'org.apache.maven.plugins:maven-compiler-plugin': POM 'org.apache.maven.plugins:maven-compiler-plugin' not found in repository: Unable to download the artifact from any repository

    org.apache.maven.plugins:maven-compiler-plugin:pom:2.0.2

    from the specified remote repositories:
    central (http://repo1.maven.org/maven2)

    for project org.apache.maven.plugins:maven-compiler-plugin

    Do u have any idea.

    ReplyDelete
  12. Sangeetha,
    Take a look at this link, sounds like you have a similar problem.
    http://stackoverflow.com/questions/1230686/sonar-maven-integration

    ReplyDelete
  13. I had a follow error: Embedded error: java.lang.ClassCastException: org.sonar.plugins.checkstyle.CheckstylePlugin cannot be cast to org.sonar.api.Plugin

    Anyone can help me?

    Tks

    ReplyDelete
  14. Great post!
    Thanks for sharing. Keep them come.

    ReplyDelete
  15. Hi Meera!

    Thank you for this post, it's really useful for me!
    Can you tell me please, where do you have your project? Mine is on ClearCase UCM and it really gets nasty when trying to configure everything.

    ReplyDelete
  16. I am using ant build in Hudson and using Sonar for a single point analysis and test repository but when I follow the step mentioned above the build is giving the following error. Could you please help me?

    [ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:1.0-beta-2:sonar (default-cli) on project Positions: Can not execute Sonar: UnsupportedOperationException -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:1.0-beta-2:sonar (default-cli) on project Positions: Can not execute Sonar
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:203)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:140)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:314)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:151)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:445)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:168)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:132)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
    Caused by: org.apache.maven.plugin.MojoExecutionException: Can not execute Sonar
    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:103)
    at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:79)
    at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:88)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:195)
    ... 19 more
    Caused by: java.lang.UnsupportedOperationException
    at org.apache.maven.plugin.internal.DefaultPluginManager.executeMojo(DefaultPluginManager.java:90)
    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:98)
    ... 23 more

    ReplyDelete
  17. Biswajit,
    Do you have Maven installed? Sonar requires Maven.

    ReplyDelete
  18. Anca,
    I have projects checked out from SVN, StarTeam and a couple other SCM tools.
    Not sure what problem you are facing?

    I also did ClearCase for one of our clients.

    ReplyDelete
  19. Hi Meera,

    I am facing same problem as Biswajit. Maven is installed and configured in Hudson and yet I see the problem. Can you help me in fixing this?

    Thanks in advance,
    Swetha.

    ReplyDelete
  20. Thank you so much.

    ReplyDelete
  21. Hi Merra,

    I am facing problem in HUDSON when I am build the code and want to publish the results to SONAR server :

    Below is the error description. Hudson is running on one system and SONAR is running on other system. configuration of SONAR plugin is done on HUDSON.
    As my project is build using ANT , so only configuration not done in HUDSON>ManageHudson>ConfigureSystem was Maven insatllation.
    Is this required and due to this only I am getting the below error.

    [workspace] $ mvn.bat -f pom.xml -e -B sonar:sonar -Dsonar.jdbc.driver=org.apache.derby.jdbc.ClientDriver -Dsonar.jdbc.url=jdbc:derby://9.182.234.46:1527/sonar;create=true ******** ******** -Dsonar.host.url=http://9.182.234.46:9000/
    The system cannot find the file specified
    FATAL: command execution failed
    java.io.IOException: CreateProcess: mvn.bat -f pom.xml -e -B sonar:sonar -Dsonar.jdbc.driver=org.apache.derby.jdbc.ClientDriver -Dsonar.jdbc.url=jdbc:derby://9.182.234.46:1527/sonar;create=true -Dsonar.jdbc.username=sonar -Dsonar.jdbc.password=sonar -Dsonar.host.url=http://9.182.234.46:9000/ error=2
    at java.lang.ProcessImpl.(ProcessImpl.java:108)
    at java.lang.ProcessImpl.start(ProcessImpl.java:56)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:466)
    at hudson.Proc$LocalProc.(Proc.java:192)
    at hudson.Proc$LocalProc.(Proc.java:164)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:638)
    at hudson.Launcher$ProcStarter.start(Launcher.java:273)
    at hudson.Launcher$ProcStarter.join(Launcher.java:280)
    at hudson.tasks.Maven.perform(Maven.java:259)
    at hudson.plugins.sonar.utils.SonarMaven.executeMaven(SonarMaven.java:89)
    at hudson.plugins.sonar.SonarPublisher.executeSonar(SonarPublisher.java:367)
    at hudson.plugins.sonar.SonarPublisher.perform(SonarPublisher.java:314)
    at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
    at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:603)
    at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:582)
    at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:560)
    at hudson.model.Build$RunnerImpl.post2(Build.java:156)
    at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:529)
    at hudson.model.Run.run(Run.java:1386)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:145)
    Finished: FAILURE

    As this issue is blocking my work can you please help me.

    thanks in advance
    Rohit Nabh

    ReplyDelete
  22. Have you installed Maven where Hudson is running?

    ReplyDelete
  23. Hi Meera,

    Yes Maven was installed when HUSDON was running.
    So I have to restart the HUDSON again.

    ReplyDelete
  24. Please, I need your help. I have followed all the steps. my project is a grails project and non maven. The result of my build with hudson is:
    [myapp] $ /usr/share/maven2/bin/mvn clean site clover2:instrument clover2:aggregate clover2:clover
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'clover2'.
    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] The plugin 'org.apache.maven.plugins:maven-clover2-plugin' does not exist or no valid version could be found
    [INFO] ------------------------------------------------------------------------
    [INFO] For more information, run Maven with the -e switch
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: < 1 second
    [INFO] Finished at: Wed Mar 30 13:41:13 CET 2011
    [INFO] Final Memory: 2M/122M
    [INFO] ------------------------------------------------------------------------
    [stmalertsweb] $ mvn -f /home/usr/ws/myapp/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 ******** ********
    + Error stacktraces are turned on.
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'sonar'.
    [INFO] Ignoring available plugin update: 2.0-beta-2 as it requires Maven version 3.0
    [INFO] Ignoring available plugin update: 2.0-beta-1 as it requires Maven version 3.0
    [INFO] ------------------------------------------------------------------------
    [INFO] Building test
    [INFO] task-segment: [sonar:sonar] (aggregator-style)
    [INFO] ------------------------------------------------------------------------
    [INFO] [sonar:sonar {execution: default-cli}]
    [INFO] Sonar host: http://localhost:9000
    [INFO] Sonar version: 2.6
    [INFO] Execute: org.codehaus.sonar:sonar-maven-plugin:2.6:sonarBut as a result I have this:

    ReplyDelete
  25. Maven is complaining about clover2 plug-in. Are you sure there is a plug-in by that name?

    Just try, mvn clean install sonar:sonar

    ReplyDelete
  26. Hi Merra,
    i have face the problem while building my project.
    where install maven in default created .hudson in C: drive or in tomcat wher deploy is done.
    plz give the exact where to pass project for analyze the code while in creating a new job or else where.
    thanks
    bipin
    bksolvent@gmail.com
    Started by user anonymous
    [workspace] $ mvn.bat -f C:\.hudson\jobs\StrutsProj123\workspace\pom.xml -e -B sonar:sonar -Dsonar.jdbc.driver=oracle.jdbc.driver.OracleDriver -Dsonar.jdbc.url=jdbc:oracle:thin:@localhost/XE ******** ********
    FATAL: command execution failed
    java.io.IOException: Cannot run program "mvn.bat" (in directory "C:\.hudson\jobs\StrutsProj123\workspace"): CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at hudson.Proc$LocalProc.(Proc.java:192)
    at hudson.Proc$LocalProc.(Proc.java:164)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:639)
    at hudson.Launcher$ProcStarter.start(Launcher.java:274)
    at hudson.Launcher$ProcStarter.join(Launcher.java:281)
    at hudson.tasks.Maven.perform(Maven.java:259)
    at hudson.plugins.sonar.utils.SonarMaven.executeMaven(SonarMaven.java:115)
    at hudson.plugins.sonar.SonarPublisher.executeSonar(SonarPublisher.java:383)
    at hudson.plugins.sonar.SonarPublisher.perform(SonarPublisher.java:330)
    at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
    at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:622)
    at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:601)
    at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:579)
    at hudson.model.Build$RunnerImpl.post2(Build.java:156)
    at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:548)
    at hudson.model.Run.run(Run.java:1386)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:145)
    Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 20 more
    Finished: FAILURE

    ReplyDelete
  27. Hi Meera,

    i'm kind of stuck, can u help me with this:

    [ERROR] No plugin found for prefix 'sonar' in the current project and in the plugin groups [org.codehaus.sonar, org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\wmakchou\.m2\repository), central (http://repo1.maven.org/maven2)] -> [Help 1]

    Thanks

    ReplyDelete
  28. Have you installed Sonar? Also, is the Sonar plugin for Hudson/Jenkins installed?

    ReplyDelete
  29. Hi,
    yes i did,i followed your steps...
    Now i'm getting this:

    [ERROR] Invalid plugin descriptor for org.codehaus.mojo:sonar-maven-plugin:2.7 (C:\Users\wmakchou\.m2\repository\org\codehaus\mojo\sonar-maven-plugin\2.7\sonar-maven-plugin-2.7.jar), Plugin's descriptor contains the wrong group ID: org.codehaus.sonar -> [Help 1]

    Thanks Meera

    ReplyDelete
  30. our Sonar and Hudson were installed at different Unix accounts on the same box. Sonar plugin has been installed on Hudson. however we got the following errors when do build. would you please advise?

    thank you very much


    [ERROR] BUILD ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] The plugin 'org.codehaus.mojo:sonar-maven-plugin' does not exist or no valid version could be found
    [INFO] ------------------------------------------------------------------------
    [INFO] Trace
    org.apache.maven.lifecycle.LifecycleExecutionException: The plugin 'org.codehaus.mojo:sonar-maven-plugin' does not exist or no valid version could be found

    ReplyDelete
  31. Hi Meera,

    I have followed you mention step and build the project successfully. But when I try to view sonar interface. There is no any result shown.

    Regars
    Ragu

    ReplyDelete
  32. Ragu,
    Do you see any error messages when you run sonar from the command line?

    ReplyDelete
  33. Anonymous,
    Check this link...
    http://docs.codehaus.org/display/SONAR/Frequently+Asked+Questions#FrequentlyAskedQuestions-Theplugin%27org.apache.maven.plugins%3Amavensonarplugin%27doesnotexistornovalidversioncouldbefound

    ReplyDelete
  34. Hi Meera,

    I would like to check with the following of your computer that you run hudson & sonar:
    (1) Processor
    (2) Memory
    (3) OS

    Thanks.

    ReplyDelete
  35. Hey Meera nice post.

    I have tried to setup Sonar with Hudson bur the Squid extraction process is throwing OutOfMemoryException.

    The trace is:

    [INFO] Java Squid scan...
    [INFO] Java Squid scan done: 54 ms
    [INFO] Squid extraction...
    [ERROR] Java heap space -> [Help 1]
    java.lang.OutOfMemoryError: Java heap space
    at java.lang.AbstractStringBuilder.(AbstractStringBuilder.java:45)
    at java.lang.StringBuilder.(StringBuilder.java:80)
    at org.sonar.batch.index.DefaultIndex.createUID(DefaultIndex.java:435)
    at org.sonar.batch.index.DefaultIndex.doIndex(DefaultIndex.java:512)
    at org.sonar.batch.index.DefaultIndex.index(DefaultIndex.java:488)
    at org.sonar.batch.DefaultSensorContext.index(DefaultSensorContext.java:56)
    at org.sonar.plugins.squid.bridges.ResourceIndex.loadSquidMethods(ResourceIndex.java:102)
    at org.sonar.plugins.squid.bridges.ResourceIndex.loadSquidResources(ResourceIndex.java:47)
    at org.sonar.plugins.squid.SquidExecutor.save(SquidExecutor.java:96)
    at org.sonar.plugins.squid.SquidSensor.analyzeMainSources(SquidSensor.java:78)
    at org.sonar.plugins.squid.SquidSensor.analyse(SquidSensor.java:61)
    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:63)
    at org.sonar.batch.phases.Phases.execute(Phases.java:93)
    at org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:145)
    at org.sonar.batch.bootstrap.Module.start(Module.java:89)
    at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:106)
    at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:96)
    at org.sonar.batch.bootstrap.Module.start(Module.java:89)
    at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:96)
    at org.sonar.batch.bootstrap.Module.start(Module.java:89)
    at org.sonar.batch.Batch.execute(Batch.java:74)
    at org.sonar.maven3.SonarMojo.executeBatch(SonarMojo.java:147)
    at org.sonar.maven3.SonarMojo.execute(SonarMojo.java:136)
    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:113)
    at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:65)
    at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:90)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    [ERROR]
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryError
    [DEBUG] Skipping watched dependency update for build: Build #16 due to result: FAILURE
    Finished: FAILURE

    Please could you help out.

    Thanks in advance

    ReplyDelete
  36. Hi Meera,
    Thanks for this great article.
    Wondering whether I could setup Hudson and Sonar on the same J2EE container (say, Weblogic 10.3.2)? In that case what is the JVM heap size that I should allocate?

    Thanks for your time.

    ReplyDelete
  37. Hi Meera,
    Thanks for this nice article. Wondering whether I could configure both Hudson and Sonar on a single Weblogic instance, and if so, what is the minimum java heap I should alocate to that JVM?

    Thanks
    Senthil Kumar Suriyanarayanan.

    ReplyDelete
  38. hello mam,
    i have following problem during building project in jenkins.

    Started by user anonymous
    Checkout:workspace / /root/.jenkins/jobs/uvyas/workspace - hudson.remoting.LocalChannel@73f61ca1
    Using strategy: Default
    Last Built Revision: Revision 447819833389ee84807e3adffdf0eb0512a2eb21 (origin/HEAD, origin/master)
    Checkout:workspace / /root/.jenkins/jobs/uvyas/workspace - hudson.remoting.LocalChannel@73f61ca1
    Fetching changes from 1 remote Git repository
    Fetching upstream changes from git@github.com:uvyas/uv.git
    Seen branch in repository origin/HEAD
    Seen branch in repository origin/master
    Commencing build of Revision 447819833389ee84807e3adffdf0eb0512a2eb21 (origin/HEAD, origin/master)
    Checking out Revision 447819833389ee84807e3adffdf0eb0512a2eb21 (origin/HEAD, origin/master)
    Warning : There are multiple branch changesets here
    [workspace] $ ant
    Error: Could not find or load main class org.apache.tools.ant.launch.Launcher
    Build step 'Invoke Ant' marked build as failure
    Finished: FAILURE

    i have set all tha path in /etc/bashrc
    and jenkins/webapps/lib also have ant.launcher.jar file.


    so plz help me out from this issue.

    ReplyDelete
  39. Hi Meera,

    We are getting below error:

    [INFO] Can not execute Sonar

    Embedded error: PicoLifecycleException: method 'public final org.sonar.core.pers
    istence.DefaultDatabase org.sonar.core.persistence.DefaultDatabase.start()', ins
    tance 'org.sonar.batch.bootstrap.BatchDatabase@5197d20c, java.lang.RuntimeExcept
    ion: wrapper
    Connection timed out: connect


    Can you please help?

    Thanks,
    Sanjiv Sharma

    ReplyDelete
  40. Hi Meera,

    Thanks for the blog it was helpfull..
    we dont use maven to build our product we use make and jenkins is our CI tool, will sonar work in such envoirment.

    can you suggest how can a make based build be setup on Jenkins with sonar..

    ReplyDelete
  41. Hi Meera,
    I am using jenkins as CI .and when i am trying to create jobs using cli as told by u
    java -jar jenkins-cli.jar -s http://localhost:8080 create-job khaja <config.xml
    it is coming as "the file specified do not exist"

    and also could u tellme configuring sonar with jenkins ..

    ReplyDelete
  42. What if the localhost for sonar shows "No data" for all the metrics on the dashboard ?

    ReplyDelete
  43. I am trying to install sonar plugin in hudson...After i restart hudson for changes, i see the below failure
    NFO: Failed to load plugin - sonar because of error Dependency maven-plugin (1.344) doesn't exist
    ul 22, 2012 2:11:40 PM hudson.model.Hudson$5 onTaskFailed
    EVERE: Failed Loading plugin sonar
    ava.io.IOException: Dependency maven-plugin (1.344) doesn't exist
    at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:435)
    at hudson.PluginManager$2$1$1.run(PluginManager.java:287)
    at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:146)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:259)
    at hudson.model.Hudson$4.runTask(Hudson.java:645)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:187)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

    ReplyDelete
  44. NFO: Failed to load plugin - sonar because of error Dependency maven-plugin (1.344) doesn't exist
    ul 22, 2012 2:11:40 PM hudson.model.Hudson$5 onTaskFailed
    EVERE: Failed Loading plugin sonar
    ava.io.IOException: Dependency maven-plugin (1.344) doesn't exist
    at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:435)
    at hudson.PluginManager$2$1$1.run(PluginManager.java:287)
    at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:146)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:259)
    at hudson.model.Hudson$4.runTask(Hudson.java:645)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:187)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

    ReplyDelete
  45. Hi Meera,

    Can we integrate sonar with svn? if yes how?

    BR,
    Sunil Garje

    ReplyDelete
  46. Hi Sunil,
    I have done this sometime back in my project.
    I followed this tutorial, hope this helps. Have your svn url, and try to follow the below.


    http://www.methodsandtools.com/tools/tools.php?sonar

    --------------------
    Use case on Apache commons-collection project

    A pre-requisite to run Sonar is to have Java and Maven installed on the box. Once this is the case, you can run Sonar in 5 simple steps:

    1. Download the distribution from http://sonar.codehaus.org/downloads/ and unzip it

    2. Open a console and start the server:

    > $SONAR_HOME\bin\windows-x86-32\StartSonar.bat on windows

    > $SONAR_HOME/bin/[OS]/sonar.sh on other platforms

    3. Open a console where you want to checkout the source and run:

    svn co http://svn.apache.org/viewvc/commons/proper/collections/trunk/.

    4. Run mvn install sonar:sonar in the same directory

    5. Browse http://localhost:9000

    ReplyDelete
  47. Hi Meera,

    Thanks a lot for the detailed explanation. Was very helpful. I have Sonar running on a remote server and have hudson configured with the plugin as you had mentioned. But when I create a job and check Sonar in the post build actions section, I am not getting the same screen as you. I have getting only a very limited fields eg: branch, MVN_OPTS, JDK etc and no place to configure the sonar project. Also, after the build, when i click on configure the job, the sonar is again unchecked. Could you please help me out here ?

    ReplyDelete
  48. What version of Hudson and Sonar are you using?

    ReplyDelete
  49. Hi Meera,

    I have been working on Hudson and sonar from sometime. Recently I have been facing the below posted issue. Kindly suggest what can be done.

    [ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project asdc-contentservlet-parent: Can not execute Sonar: Fail to install plugin: DefaultPluginMetadata[key=findbugs,version=3.0]: No space left on device -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project asdc-contentservlet-parent: Can not execute Sonar
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217).....

    Caused by: java.io.IOException: No space left on device

    Regards,
    Halini
    at java.io.FileOutputStream.writeBytes(Native Method)
    at java.io.FileOutputStream.write(FileOutputStream.java:282)
    at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1263)
    at org.apache.commons.io.IOUtils.copy(IOUtils.java:1236)
    at org.sonar.api.utils.ZipUtils.unzip(ZipUtils.java:91)
    at org.sonar.core.plugins.PluginInstaller.copyDependencies(PluginInstaller.java:80)
    at org.sonar.core.plugins.PluginInstaller.install(PluginInstaller.java:52)
    ... 46 more

    ReplyDelete
    Replies
    1. I am guessing the machine running Hudson, Sonar and Maven has no space. Check this link for more information:
      http://www.ivankuznetsov.com/2010/02/no-space-left-on-device-running-out-of-inodes.html

      Delete
  50. Hello Meera!

    Thanks for this quite nice article. I am trying out to have Sonar analysis but with a slight different project configuration.

    I have two different maven projects, which are clubbed together as a single build project in Jenkins. So the common build project does checkout the two source repositories and makes the build.

    But when it comes to the Sonar plugin for doing an analysis of both the projects, I don't know how to configure it.

    While configuring the Sonar plugin, there is a Root POM field, which I am not sure how to fill up.

    Can you help with how to do configuration for such a project with more than one root pom files.

    Thank you
    Rajesh
    rab@unwire.com

    ReplyDelete
  51. Hi Meera,

    I am getting below error while running sonar.
    Unable to find resource 'org.codehaus.mojo:sonar-maven-plugin:maven-plugin:1.0'

    A required plugin was not found: Plugin could not be found - check that the goal name is correct: Unable to download the artifact from any repository

    Try downloading the file manually from the project website.

    Then, install it using the command:
    mvn install:install-file -DgroupId=org.codehaus.mojo -DartifactId=sonar-maven-plugin -Dversion=1.0 -Dpackaging=maven-plugin -Dfile=/path/to/file

    Alternatively, if you host your own repository you can deploy the file there:
    mvn deploy:deploy-file -DgroupId=org.codehaus.mojo -DartifactId=sonar-maven-plugin -Dversion=1.0 -Dpackaging=maven-plugin -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]


    org.codehaus.mojo:sonar-maven-plugin:maven-plugin:1.0

    Please Help..
    Thanks
    Amit

    ReplyDelete
  52. SONAR ANALYSIS FAILED
    ------------------------------------------------------------------------
    FATAL: Sonar runner executable was not found for Sonar Runner
    Skipping sonar analysis due to bad build status FAILURE
    [DEBUG] Skipping watched dependency update for build: TestHybris #21 due to result: FAILURE
    Finished: FAILURE

    ReplyDelete