New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot configure the 'publishing' extension after it has been accessed. #125

Closed
alibkord opened this Issue Aug 17, 2015 · 12 comments

Comments

Projects
None yet
6 participants
@alibkord

alibkord commented Aug 17, 2015

build.gradle:

buildscript {
    repositories {
        jcenter()
        mavenLocal()
    }

    dependencies {
        classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
        classpath 'net.researchgate:gradle-release:2.2.0'
    }
}

apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'net.researchgate.release'

...

publishing {
    repositories {
        maven {
            name "<repo-name>"
            url "<repo-url>"
        }
    }
    publications {
        aarArchive(MavenPublication) {
            artifactId = '<artifact-name>'
            artifact("build/outputs/aar/library-release.aar") {
                extension "aar"
            }
            pom.withXml {
                def pomXml = asNode()
                pomXml.appendNode('name', '<Artifact Name>')
                pomXml.appendNode('description',
                        'An Android library (.aar) used to integrate ' +
                                '<description>')
                def parentPomNode = pomXml.appendNode('parent')
                parentPomNode.appendNode('groupId', parentPomGroupId)
                parentPomNode.appendNode('artifactId', parentPomArtifactId)
                parentPomNode.appendNode('version', parentPomVersion)
            }
        }
    }
}
...

When running ./gradlew release:

* What went wrong:
A problem occurred evaluating project ':library'.
> Cannot configure the 'publishing' extension after it has been accessed.

And with debug and stacktrace on:

20:35:08.512 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
20:35:08.512 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred evaluating project ':library'.
20:35:08.512 [ERROR] [org.gradle.BuildExceptionReporter] > Cannot configure the 'publishing' extension after it has been accessed.
20:35:08.512 [ERROR] [org.gradle.BuildExceptionReporter]
20:35:08.512 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
20:35:08.513 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.GradleScriptException: A problem occurred evaluating project ':library'.
20:35:08.513 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
20:35:08.514 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:148)
20:35:08.514 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:39)
20:35:08.514 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
20:35:08.514 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
20:35:08.514 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:59)
20:35:08.514 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:504)
20:35:08.515 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:83)
20:35:08.515 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:47)
20:35:08.515 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:85)
20:35:08.515 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:76)
20:35:08.515 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.commandline.CommandLineTaskParser.parseTasks(CommandLineTaskParser.java:42)
20:35:08.515 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.TaskNameResolvingBuildConfigurationAction.configure(TaskNameResolvingBuildConfigurationAction.java:44)
20:35:08.516 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
20:35:08.516 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.access$100(DefaultBuildExecuter.java:23)
20:35:08.516 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:48)
20:35:08.516 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.ExcludedTaskFilteringBuildConfigurationAction.configure(ExcludedTaskFilteringBuildConfigurationAction.java:47)
20:35:08.516 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
20:35:08.517 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.access$100(DefaultBuildExecuter.java:23)
20:35:08.517 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:48)
20:35:08.517 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultTasksBuildExecutionAction.configure(DefaultTasksBuildExecutionAction.java:44)
20:35:08.517 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
20:35:08.517 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.select(DefaultBuildExecuter.java:35)
20:35:08.517 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
20:35:08.518 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
20:35:08.518 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
20:35:08.518 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
20:35:08.518 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
20:35:08.518 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
20:35:08.518 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
20:35:08.519 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
20:35:08.519 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
20:35:08.519 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
20:35:08.519 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
20:35:08.519 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
20:35:08.519 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
20:35:08.520 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
20:35:08.520 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
20:35:08.520 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
20:35:08.520 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
20:35:08.521 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
20:35:08.521 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
20:35:08.521 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.util.Swapper.swap(Swapper.java:38)
20:35:08.521 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
20:35:08.521 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
20:35:08.522 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
20:35:08.522 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
20:35:08.522 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
20:35:08.522 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
20:35:08.522 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
20:35:08.523 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
20:35:08.523 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
20:35:08.523 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
20:35:08.523 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:46)
20:35:08.523 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
20:35:08.523 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
20:35:08.524 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.api.InvalidUserDataException: Cannot configure the 'publishing' extension after it has been accessed.
20:35:08.524 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.plugins.ExtensionsStorage$DeferredConfigurableExtensionHolder.configureLater(ExtensionsStorage.java:174)
20:35:08.524 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.plugins.ExtensionsStorage$DeferredConfigurableExtensionHolder.configure(ExtensionsStorage.java:168)
20:35:08.524 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.plugins.ExtensionsStorage.configureExtension(ExtensionsStorage.java:69)
20:35:08.524 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.plugins.DefaultConvention$ExtensionsDynamicObject.invokeMethod(DefaultConvention.java:207)
20:35:08.525 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
20:35:08.525 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:79)
20:35:08.525 [ERROR] [org.gradle.BuildExceptionReporter]    at build_8dwqa41ytgl29bu4nv7mrfvhb.run(/Users/akord/src/atlassian-account-android-library/library/build.gradle:60)
20:35:08.525 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
20:35:08.525 [ERROR] [org.gradle.BuildExceptionReporter]    ... 55 more
20:35:08.525 [ERROR] [org.gradle.BuildExceptionReporter]
20:35:08.526 [LIFECYCLE] [org.gradle.BuildResultLogger]
20:35:08.526 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
@danez

This comment has been minimized.

Show comment
Hide comment
@danez

danez Aug 17, 2015

Contributor

How do you hook up the publishing extension with the release? I don't see any dependsOn or anything like that.

Contributor

danez commented Aug 17, 2015

How do you hook up the publishing extension with the release? I don't see any dependsOn or anything like that.

@alibkord

This comment has been minimized.

Show comment
Hide comment
@alibkord

alibkord Aug 17, 2015

I didn't hook it up. Do I have to? I assumed there was no intrinsic dependency between them.
Based on my experience with maven's release plugin, I thought all the release plugin does is bumping up the version and pushing to scm.
As you can see I'm not running the publish/deploy when I get that error which is why I was confused what the connection is there.

alibkord commented Aug 17, 2015

I didn't hook it up. Do I have to? I assumed there was no intrinsic dependency between them.
Based on my experience with maven's release plugin, I thought all the release plugin does is bumping up the version and pushing to scm.
As you can see I'm not running the publish/deploy when I get that error which is why I was confused what the connection is there.

@danez

This comment has been minimized.

Show comment
Hide comment
@danez

danez Aug 17, 2015

Contributor

The release plugin is not doing anything with the publish plugin. Are you sure the error appeared when you added the release plugin?

Contributor

danez commented Aug 17, 2015

The release plugin is not doing anything with the publish plugin. Are you sure the error appeared when you added the release plugin?

@gariem

This comment has been minimized.

Show comment
Hide comment
@gariem

gariem Aug 17, 2015

I have the same issue, by just adding the plugin to the build.gradle file I got the same message "Cannot configure the 'publishing' extension after it has been accessed."

gariem commented Aug 17, 2015

I have the same issue, by just adding the plugin to the build.gradle file I got the same message "Cannot configure the 'publishing' extension after it has been accessed."

@danez

This comment has been minimized.

Show comment
Hide comment
@danez

danez Aug 17, 2015

Contributor

Was it working with versions before 2.2?

Contributor

danez commented Aug 17, 2015

Was it working with versions before 2.2?

@danez

This comment has been minimized.

Show comment
Hide comment
@danez

danez Aug 17, 2015

Contributor

Ok as far as i can tell it is an issue with the order of plugins. Or at least this is a workaround to apply maven-publish after the release plugin. I will see if i can fix that.

https://discuss.gradle.org/t/apply-maven-publish-plugin-from-init-script/2460

Contributor

danez commented Aug 17, 2015

Ok as far as i can tell it is an issue with the order of plugins. Or at least this is a workaround to apply maven-publish after the release plugin. I will see if i can fix that.

https://discuss.gradle.org/t/apply-maven-publish-plugin-from-init-script/2460

@danez danez added this to the 2.2.1 milestone Aug 17, 2015

@danez

This comment has been minimized.

Show comment
Hide comment
@danez

danez Aug 17, 2015

Contributor

Ok I reproduced and fixed it in 4d31ad7. will be part of 2.2.1

Contributor

danez commented Aug 17, 2015

Ok I reproduced and fixed it in 4d31ad7. will be part of 2.2.1

@danez danez closed this Aug 17, 2015

@gariem

This comment has been minimized.

Show comment
Hide comment
@gariem

gariem Aug 17, 2015

correct, I just tried and release-plugin should be placed before maven-publish plugin

gariem commented Aug 17, 2015

correct, I just tried and release-plugin should be placed before maven-publish plugin

@alibkord

This comment has been minimized.

Show comment
Hide comment
@alibkord

alibkord Aug 17, 2015

Thanks a lot guys.

alibkord commented Aug 17, 2015

Thanks a lot guys.

@Krijger

This comment has been minimized.

Show comment
Hide comment
@Krijger

Krijger Sep 16, 2016

People that run into "Cannot configure the 'publishing' extension after it has been accessed" google their way here, so I'll document an issue that had me going for quite a while.

project.publishing {
  repositories {
    maven {
      ...
    }
  }
}

is NOT the same as

project.publishing.repositories  {
  maven {
    ...
  }
}

The latter accessed the publishing Extension object which makes you run intor this issue.

Krijger commented Sep 16, 2016

People that run into "Cannot configure the 'publishing' extension after it has been accessed" google their way here, so I'll document an issue that had me going for quite a while.

project.publishing {
  repositories {
    maven {
      ...
    }
  }
}

is NOT the same as

project.publishing.repositories  {
  maven {
    ...
  }
}

The latter accessed the publishing Extension object which makes you run intor this issue.

@childnode

This comment has been minimized.

Show comment
Hide comment
@childnode

childnode Feb 22, 2018

This is still an issue in gradle 4.5 with

apply plugin: "maven-publish"
publishing {
    publications {
        …
    }

    repositories {
        maven {
            …
        }
    }
}

then calling

publishing {
  publications {
    …
  }
}

and "fixed" by using publishing.publications { … } secondly as described above and in stackoverflow

childnode commented Feb 22, 2018

This is still an issue in gradle 4.5 with

apply plugin: "maven-publish"
publishing {
    publications {
        …
    }

    repositories {
        maven {
            …
        }
    }
}

then calling

publishing {
  publications {
    …
  }
}

and "fixed" by using publishing.publications { … } secondly as described above and in stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment