Gradle 3.2.1 with Java 1.8
So we are providing multiple plugins as part of our enterprise suite of Gradle plugins. We hava a java plugin & a war plugin. Our java plugin applies Gradle’s Java plugin and then does some other stuff. Our war plugin applies our java plugin & Gradle’s war plugin, then does some other stuff.
One thing our Java plugin (Groovy class that implements Plugin does is configure the publications. We are doing this:
project.extensions.configure(PublishingExtension, ConfigureUtil.configureUsing {
publications.create('mainJava', MavenPublication) {
from project.components.java
artifact project.tasks[SOURCESJAR_TASK_NAME]
artifact project.tasks[JAVADOCJAR_TASK_NAME]
pom.withXml {
PluginHelper.fixMavenPomDependencySection(project, asNode(), *configurationsForPom)
}
}
})
In our war plugin, we don’t want to publish the components.java - instead we publish the components.web, so we are trying to remove the mainJava publication & introduce a new one:
project.extensions.configure(PublishingExtension, ConfigureUtil.configureUsing {
publications.create('mainWar', MavenPublication) {
from project.components.web
artifact project.tasks['sourcesJar']
artifact project.tasks['javadocJar']
pom.withXml {
PluginHelper.fixMavenPomDependencySection(project, asNode(), *configurationsForPom)
}
}
})
When I do this though I get this error:
Caused by: org.gradle.api.InvalidUserDataException: Cannot configure the 'publishing' extension after it has been accessed.
at org.gradle.api.internal.plugins.ExtensionsStorage$DeferredConfigurableExtensionHolder.configureLater(ExtensionsStorage.java:174)
at org.gradle.api.internal.plugins.ExtensionsStorage$DeferredConfigurableExtensionHolder.configure(ExtensionsStorage.java:168)
at org.gradle.api.internal.plugins.ExtensionsStorage.configureExtension(ExtensionsStorage.java:73)
at org.gradle.api.internal.plugins.DefaultConvention.configure(DefaultConvention.java:129)
at org.gradle.api.plugins.ExtensionContainer$configure.call(Unknown Source)
at my.company.gradle.build.plugin.WarPlugin.configurePublications(WarPlugin.groovy:60)
at my.company.gradle.build.plugin.WarPlugin.apply(WarPlugin.groovy:27)
at my.company.gradle.build.plugin.WarPlugin.apply(WarPlugin.groovy)
at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(ImperativeOnlyPluginApplicator.java:35)
at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImperative(RuleBasedPluginApplicator.java:43)
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:139)
Line 60 of my WarPlugin is the line
project.extensions.configure(PublishingExtension, ConfigureUtil.configureUsing {
Any ways I should be doing this?