Gradle Sonar plugin broken with Sonar 3.4?

We are using Gradle 1.3. We upgraded our Sonar installation from 3.3 to 3.4 and now the Sonar plugin fails with a ClassNotFoundException when the Sonar Batch is trying to “Install plugins”:

Caused by: org.sonar.api.utils.SonarException: Fail to load plugin findbugs

at org.sonar.core.plugins.PluginClassloaders.instantiatePlugin(

at org.sonar.core.plugins.PluginClassloaders.init(

at org.sonar.batch.bootstrap.BatchPluginRepository.doStart(

at org.sonar.batch.bootstrap.BatchPluginRepository.start(

at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(

… 82 more Caused by: java.lang.NoClassDefFoundError: org/sonar/api/SonarPlugin

at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(

at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(

at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(

at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(

at org.sonar.core.plugins.PluginClassloaders.instantiatePlugin(

… 86 more Caused by: java.lang.ClassNotFoundException: org.sonar.api.SonarPlugin

at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(

at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(

at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(

… 91 more

The same problem is reproducible on my local maschine with a clean Sonar 3.4 installation and the Gradle sample project located in the distribution under samples/sonar/quickstart. But running Sonar on that sample project by using the Sonar Ant tasks did work.

I am not sure if this a problem of the new Sonar version or an incompatibility between the Gradle Sonar plugin and the new Sonar version…

Please help…

thanks for reporting this. I’ll have a look on this in the next couple of days and give you feedback.

cheers, Rene

We are having the exact same issue. I know you are looking into it so I will deactivate for now or roll back the sonar install for a while.

We are also having the same problem. Please let me know when a solution becomes available.

The Sonar plugin will have to undergo bigger changes to work with Sonar 3.4 and higher. Given that Gradle 1.4 is almost out, this will have to wait at least until 1.5.

Thanks for the information, Peter!

For those of you who don´t want to downgrade your Sonar installation back to <3.4 I have worked out a temporary workaround that hopefully is not too much efford and greatly demonstrates the strenghts of Gradle’s Ant integration :wink: This is intended to be a relatively simple workaround until Gradle supports Sonar 3.4 again. Unfortunately you need to pass your project settings manually instead of using the Gradle objects, but I guess for most projects it is worth a consideration.

Basic idea is to replace the broken sonarAnalyze task by a custom task that uses the original Sonar Ant task. I am using this solution on a multiproject build and I even did not need to change my CI config because the command line call stays the same.

I hope this helps, greetings to all Gradlers out there! Bernd Steinert

To replace the gradle plugin change the line “apply plugin: ‘sonar’” to “apply from ‘sonar.gradle’” in your build file(s).


apply plugin: 'java'
  repositories {
  configurations {
  dependencies {
    sonar group: 'org.codehaus.sonar-plugins', name: 'sonar-ant-task', version: '2.0'
  task sonarAnalyze << {
      // define the Sonar properties according to Sonar Ant task documentation[''] = 'http://localhost:9000/sonar'
          // define multi-project modules['sonar.modules'] = 'mod1,mod2,mod3'
          // define module specific properties['mod1.sonar.sources'] = 'other/src/folder'['mod2.sonar.sources'] = 'src,multiple/src/folders'
      ant.taskdef(name: 'sonar', classname: 'org.sonar.ant.SonarTask', classpath: configurations.sonar.asPath)

Thanks for the workaround, I’ll give it a try. Peter, do you already have a JIRA to track the necessary changes to support sonar 3.4+?


The work is already mostly done. You can try it in the latest nightly.

I’ve linked this to GRADLE-2657. Fix will be included in 1.5.

Peter, thanks for fixing this. Are you able to point us to a nightly build of this plugin. I assume we can just reference the sonar plugin rather than running an entire gradle 1.5-SNAPSHOT?

Since the plugin is part of the Gradle distribution, you’ll have to switch to a nightly Gradle build to give it a try. This is as easy as pointing your wrapper to a new location. (Needless to say, nightly builds aren’t intended for production use.) Note that we eventually decided to add a new plugin (‘sonar-runner’) rather than changing the old one. You can read more about it in the nightly user guide. Note that the new plugin is incubating and things may still change, especially until 1.5 is released.

We are grateful for any feedback on the new ‘sonar-runner’ plugin.

Thank you for fixing this.

I used the nightly build gradle-1.5-20130213172554 and got sonarRunner task to work and upload results to the sonar database.

Referring to :

I change the variable names to:

’ property “sonar.jdbc.username”, “Fred Flintstone” property “sonar.jdbc.password”, “very clever”’