[GRADLE-1813] Sonar fails on nested multiproject builds Created: 28/Sep/11  Updated: 04/Jan/13  Resolved: 13/Jan/12

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-milestone-5
Fix Version/s: 1.0-milestone-8

Type: Bug
Reporter: René Gröschke (Inactive) Assignee: Unassigned
Resolution: Not A Bug Votes: 2


 Description   

When applying the sonar plugin to the gradle sample project (subprojects/docs/samples/java/multiproject) the build fails with the message:
There's an extension registered with name 'sonar'. You should not reassign it via a property setter.

It seems that applying the Plugin to (:services:shared) fails because the plugin was already applied to (:shared). INMHO, the full qualified project name is not considered. Find the full stack trace below:

org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'multiproject'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127)
at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)
at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:474)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:73)
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)
at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:38)
at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:35)
at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:450)
at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:445)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:138)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:109)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:77)
at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:42)
at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:28)
at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:32)
at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:21)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:231)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:215)
at org.gradle.launcher.Main.execute(Main.java:57)
at org.gradle.launcher.Main.main(Main.java:42)
Caused by: java.lang.IllegalArgumentException: There's an extension registered with name 'sonar'. You should not reassign it via a property setter.
at org.gradle.api.internal.plugins.ExtensionsStorage.checkExtensionIsNotReassigned(ExtensionsStorage.java:49)
at org.gradle.api.internal.plugins.DefaultConvention.propertyMissing(DefaultConvention.java:95)
at org.gradle.api.plugins.sonar.SonarPlugin.configureSonarRootModel(SonarPlugin.groovy:54)
at org.gradle.api.plugins.sonar.SonarPlugin.this$2$configureSonarRootModel(SonarPlugin.groovy)
at org.gradle.api.plugins.sonar.SonarPlugin$this$2$configureSonarRootModel.callCurrent(Unknown Source)
at org.gradle.api.plugins.sonar.SonarPlugin.apply(SonarPlugin.groovy:42)
at org.gradle.api.plugins.sonar.SonarPlugin.apply(SonarPlugin.groovy)
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.providePlugin(DefaultProjectsPluginContainer.java:107)
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.addPluginInternal(DefaultProjectsPluginContainer.java:71)
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.apply(DefaultProjectsPluginContainer.java:37)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:101)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:32)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:72)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:114)
at org.gradle.api.internal.project.AbstractProject.apply(AbstractProject.java:841)
at build_5cq9j6nrhfkicsrn91fucm243h$_run_closure1.doCall(/Users/Rene/temp/multiproject/build.gradle:4)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:112)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:61)
at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:861)
at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:866)
at org.gradle.api.internal.project.AbstractProject.subprojects(AbstractProject.java:849)
at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:158)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:93)
at org.gradle.api.internal.project.DefaultProject_Decorated.invokeMethod(Unknown Source)
at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.groovy:72)
at build_5cq9j6nrhfkicsrn91fucm243h.run(/Users/Rene/temp/multiproject/build.gradle:2)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 23 more



 Comments   
Comment by Rob Kirkbride [ 09/Oct/11 ]

I've hit this as well in milestone 5 nightly. Unless there's a workaround, it's a show stopper for us moving to milestone 5.

Comment by René Gröschke (Inactive) [ 17/Oct/11 ]

With the latest snapshot I've found a convenient 'workaround' for this.
You can apply the sonar plugin to the root project. Running "sonarAnalyze" task on your multi project build considers now all related submodules.

It should be well documented, that the sonar plugin for multi projects shall be applied to the root project only. Maybe I find the time to create a pull request for this. IMHO there are be two ways to solve issue:
1. Provide the "old" sonar behaviour for sonar plugins applied to sub projects. This means considering each submodule as a separate project in sonar.
2. Refactor the error message mentioned above, as this message is not very helpful for fixing this issue.

regards,
Rene

Comment by Gunnar Hillert [ 10/Jan/12 ]

In my opinion both use-cases should be possible. Usually I do want to run Sonar globally from the Root project as part of a nightly build. However, throughout the day I may run the Sonar task locally to get a report for a sub-module without have to through the pain of running the entire build.

This has been working fine in Maven based builds and should also be supported by Gradle.

Comment by Peter Niederwieser [ 13/Jan/12 ]

It's already supported. If you apply the plugin to the root project, you can analyze just a subproject. What you cannot do is apply the plugin both to a parent and a child project. The plugin is not supposed to be used like that.

Comment by Peter Niederwieser [ 13/Jan/12 ]

Apparently I was wrong about this. Seems there is no easy way to have both things. If you want this, please create a feature request. It's not something that's easy to implement though.

Comment by Peter Niederwieser [ 13/Jan/12 ]

What you can do is to apply the plugin to each leaf project. This is how the first version of the plugin worked. Drawbacks are that you get no accumulated view in the Sonar web interface and that analysis takes longer and requires more memory.

Comment by Peter Niederwieser [ 13/Jan/12 ]

Works as designed. I'll add some clarifying words to the user guide.

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