Error - apply a plugin into a gradle init file (gradle 2.7) - extension with name 'sonarqube', as there is an extension already registered with that name

sonarqube

(NIC) #1

Hi
We’re trying to apply the gradle sonarqube plugin to a bunch of projects all executed along with an init file. Our plan is to centralize most of the sonar configuration in the init file. We’d like to avoid the edition of 100’s of gradle build files and have the plugin “apply” call occur in the init file. All we ll have to do ideally is to pass the sonarqube parameter in the command line.

For that I have read the documentation at https://docs.gradle.org/2.7/userguide/init_scripts.html which explains how to do that. At the moment we re seeing an error

[ERROR] [org.gradle.BuildExceptionReporter] Failed to apply plugin [class ‘org.sonarqube.gradle.SonarQubePlugin’]
[ERROR] [org.gradle.BuildExceptionReporter] > Cannot add extension with name ‘sonarqube’, as there is an extension already registered with that name.

more logs below

init file :
dependencies, repos :

initscript {
repositories {
maven { url ‘http://—ourmavenl’ }
}
dependencies {
classpath group: ‘org.sonarsource.scanner.gradle’, name: ‘sonarqube-gradle-plugin’, version: ‘1.2’
}
}
then later in the init script :

allprojects{
apply plugin: org.sonarqube.gradle.SonarQubePlugin
sonarqube {
properties {
property “sonar.host.url”, "http://oursonarurl"
property “sonar.projectKey”, "$project.projectgroup:$project.projectname"
property “sonar.projectName”, "$project.projectname"
property “sonar.projectVersion”, "$project.version"
etc.
}
}
}

Full stacktrace

  • Exception is:
    Gradle failure report] 20:29:17.578 [ERROR] [org.gradle.BuildExceptionReporter]
    [20:29:17] 20:29:17.580 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
    [20:29:17] 20:29:17.580 [ERROR] [org.gradle.BuildExceptionReporter]
    [20:29:17] 20:29:17.580 [ERROR] [org.gradle.BuildExceptionReporter] * Where:
    [20:29:17] 20:29:17.580 [ERROR] [org.gradle.BuildExceptionReporter] Initialization script ‘/apps/tools/gradle/gradle-2.7/init.d/init.gradle’ line: 126
    [20:29:17] 20:29:17.580 [ERROR] [org.gradle.BuildExceptionReporter]
    [20:29:17] 20:29:17.581 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
    [20:29:17] 20:29:17.582 [ERROR] [org.gradle.BuildExceptionReporter] Failed to apply plugin [class ‘org.sonarqube.gradle.SonarQubePlugin’]
    [20:29:17] 20:29:17.582 [ERROR] [org.gradle.BuildExceptionReporter] > Cannot add extension with name ‘sonarqube’, as there is an extension already registered with that name.
    [20:29:17] 20:29:17.582 [ERROR] [org.gradle.BuildExceptionReporter]

[20:29:17] 20:29:17.583 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [class ‘org.sonarqube.gradle.SonarQubePlugin’]
[20:29:17] 20:29:17.583 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:160)
[20:29:17] 20:29:17.583 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:116)
[20:29:17] 20:29:17.583 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyType(DefaultObjectConfigurationAction.java:122)
[20:29:17] 20:29:17.583 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:106)
[20:29:17] 20:29:17.584 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$100(DefaultObjectConfigurationAction.java:35)
[20:29:17] 20:29:17.584 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$2.run(DefaultObjectConfigurationAction.java:70)
[20:29:17] 20:29:17.584 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:135)
[20:29:17] 20:29:17.584 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:46)
[20:29:17] 20:29:17.584 [ERROR] [org.gradle.BuildExceptionReporter] at init_2nb1xxwssrjecb77eecpsu6gq$_run_closure4.doCall(/apps/tools/gradle/gradle-2.7/init.d/init.gradle:126)
[20:29:17] 20:29:17.584 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:67)
[20:29:17] 20:29:17.584 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:467)
[20:29:17] 20:29:17.584 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:462)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.invocation.DefaultGradle$2.execute(DefaultGradle.java:126)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.invocation.DefaultGradle$2.execute(DefaultGradle.java:124)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.listener.ActionBroadcast.execute(ActionBroadcast.java:39)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.invocation.DefaultGradle$1.projectsLoaded(DefaultGradle.java:72)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:44)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:79)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:30)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
[20:29:17] 20:29:17.585 [ERROR] [org.gradle.BuildExceptionReporter] at com.sun.proxy.$Proxy10.projectsLoaded(Unknown Source)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.NotifyingSettingsLoader.findAndLoadSettings(NotifyingSettingsLoader.java:36)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:120)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:33)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:100)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:94)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:94)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:83)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:94)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
[20:29:17] 20:29:17.586 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:77)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:47)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:51)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:28)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:170)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
[20:29:17] 20:29:17.587 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
[20:29:17] 20:29:17.588 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
[20:29:17] 20:29:17.588 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
[20:29:17] 20:29:17.588 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
[20:29:17] 20:29:17.588 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
[20:29:17] 20:29:17.588 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.Main.doAction(Main.java:33)
[20:29:17] 20:29:17.588 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
[20:29:17] 20:29:17.588 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
[20:29:17] 20:29:17.588 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
[20:29:17] 20:29:17.589 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
[20:29:17] 20:29:17.589 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.IllegalArgumentException: Cannot add extension with name ‘sonarqube’, as there is an extension already registered with that name.
[20:29:17] 20:29:17.589 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.ExtensionsStorage.add(ExtensionsStorage.java:38)
[20:29:17] 20:29:17.589 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultConvention.add(DefaultConvention.java:101)
[20:29:17] 20:29:17.589 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultConvention.create(DefaultConvention.java:107)
[20:29:17] 20:29:17.589 [ERROR] [org.gradle.BuildExceptionReporter] at org.sonarqube.gradle.SonarQubePlugin.apply(SonarQubePlugin.java:108)
[20:29:17] 20:29:17.589 [ERROR] [org.gradle.BuildExceptionReporter] at org.sonarqube.gradle.SonarQubePlugin.apply(SonarQubePlugin.java:63)
[20:29:17] 20:29:17.589 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(ImperativeOnlyPluginApplicator.java:35)
[20:29:17] 20:29:17.589 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImperative(RuleBasedPluginApplicator.java:43)
[20:29:17] 20:29:17.589 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:144)
[20:29:17] 20:29:17.590 [ERROR] [org.gradle.BuildExceptionReporter] … 55 more
[20:29:17] 20:29:17.590 [ERROR] [org.gradle.BuildExceptionReporter]


Please confirm it is NOT possible to apply a plugin in a init file