[GRADLE-2657] Gradle Sonar plugin broken with Sonar 3.4 Created: 27/Jan/13  Updated: 15/Mar/13  Resolved: 27/Jan/13

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 1.5-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Fixed Votes: 0


 Description   

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(PluginClassloaders.java:229)
at org.sonar.core.plugins.PluginClassloaders.init(PluginClassloaders.java:97)
at org.sonar.batch.bootstrap.BatchPluginRepository.doStart(BatchPluginRepository.java:82)
at org.sonar.batch.bootstrap.BatchPluginRepository.start(BatchPluginRepository.java:63)
at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
... 82 more
Caused by: java.lang.NoClassDefFoundError: org/sonar/api/SonarPlugin
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:386)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
at org.sonar.core.plugins.PluginClassloaders.instantiatePlugin(PluginClassloaders.java:222)
... 86 more
Caused by: java.lang.ClassNotFoundException: org.sonar.api.SonarPlugin
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
... 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...



 Comments   
Comment by Gradle Forums [ 27/Jan/13 ]

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

cheers,
Rene

Comment by Gradle Forums [ 27/Jan/13 ]

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.

Comment by Gradle Forums [ 27/Jan/13 ]

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

Comment by Gradle Forums [ 27/Jan/13 ]

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.

Comment by Gradle Forums [ 27/Jan/13 ]

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

sonar.gradle:

apply plugin: 'java'

repositories {
mavenCentral()
}

configurations {
sonar
}

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
ant.properties['sonar.host.url'] = 'http://localhost:9000/sonar'
...

// define multi-project modules
ant.properties['sonar.modules'] = 'mod1,mod2,mod3'

// define module specific properties
ant.properties['mod1.sonar.sources'] = 'other/src/folder'
ant.properties['mod2.sonar.sources'] = 'src,multiple/src/folders'

ant.taskdef(name: 'sonar', classname: 'org.sonar.ant.SonarTask', classpath: configurations.sonar.asPath)

ant.sonar()
}

Comment by Gradle Forums [ 27/Jan/13 ]

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+?

Oliver

Comment by Gradle Forums [ 27/Jan/13 ]

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

Comment by rafal [ 13/Mar/13 ]

Is this fixed in 1.5-rc-1? I still have the same problem using gradle-1.5-rc-1 with sonar 3.4.1.

Comment by Yuriy Malchenko [ 14/Mar/13 ]

Trying gradle-1.5-rc-1: plugin doesn't seem to work with Sonar 3.5 (same exception).

Comment by Matt Bellinger [ 14/Mar/13 ]

Just to make sure, when you tried gradle-1.5-rc-1, did you change to using the sonar-runner plugin instead of the sonar plugin? 1.5-rc-1 introduced the sonar-runner plugin, and it is working for me.

http://www.gradle.org/docs/release-candidate/userguide/sonar_runner_plugin.html

Comment by rafal [ 15/Mar/13 ]

No, stupid me - I didn't know I have to use sonar-runner. I'll try it, thanks!

Generated at Wed Jun 30 12:27:53 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.