"Cannot configure the 'publishing' extension after it has been accessed." error since 4.8

I tried moving Hibernate to Gradle 4.8 but run into a new “Cannot configure the ‘publishing’ extension after it has been accessed.” error during initialization. It happens on a call to org.gradle.api.Project#evaluationDependsOn[1]. This worked fine in 4.7 and earlier.

[1] https://github.com/hibernate/hibernate-orm/blob/master/documentation/documentation.gradle#L25

May be related to something calling project.properties realizes the deferred configuration.

See details in: https://github.com/etiennestuder/gradle-credentials-plugin/issues/22

Haven’t checked whether this is a regression specific to 4.8 though…

Are you sure you didn’t change anything else or upgrade some plugin that calls Project.getProperties or similar? Nothing should change if you just upgrade Gradle.

@st_oehme 100% sure. In fact the only thing I changed is the url in gradlew.properties.

That would be a bug then, I’ll have a look.

Actually, publishing-pom.gradle was relying on a subtle ordering that we changed. It was executed before plugin publishing was configured. This means this script was silently ignoring the plugin marker publications that are created by the java-gradle-plugin plugin. Assuming that no one will add more publications in afterEvaluate {} does not hold. Luckily, what you want to do needs no afterEvaluate {}.

The whole XML descriptor modification doesn’t need to be in an afterEvaluate, as it only runs at execution time anyway. And the publication count check could be implemented with an .all {} hook instead of checking the size at a particular point in time, e.g.

publishing {
  int count = 0
  publications.all {
    if (++count > 1) { boom }
  }
}

You may want to migrate away from the XML hook and use the new DSL methods to simplify this script further. Also the “compile” scope workaround at the very bottom is no longer needed.

I started working on your suggestions. They seem to have fixed the issue. I am still having errors from a plugin we use since the upgrade, but the plugin author is looking into that

Thanks @st_oehme

1 Like