Custom gradle plugin calls: Unable to configure publication extension

I have a custom gradle plugin that adds custom task types and gradle to it. When I apply this plugin before maven-publish , it works fine. But when I add it after apply plugin: 'maven-publish' , it crashes with an error message:

 FAILURE: Build failed with an exception. * Where: Build file '/scratch/skgupta/git_storage/emdi/integtest/build.gradle' line: 38 * What went wrong: A problem occurred evaluating root project 'integtest'. > Cannot configure the 'publishing' extension after it has been accessed. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 7.6 secs 

Here is the build.gradle file.

 buildscript { repositories { maven { url = "${artifactory_contextUrl}/repo" } } dependencies { classpath group: 'com.mycomp.proj', name: 'MyCustomPlugin', version: "${pluginVersion}", transitive: true } } apply plugin: 'java' apply plugin: 'maven-publish' apply plugin: 'MyCustomPlugin' // WHen this line is moved above maven-publish, build works fine. // add jar name and version jar.archiveName='lrgemaas_small_deploy_3n.jar' group = 'com.mycom.proj.test' version = '1.0.3' dependencies { compile group: 'eaas.platform', name: 'registry-lookup-client', version: '0.1' compile group: 'eaas.platform', name: 'registry-client', version: '0.1' compile configurations.lrgConfig // This configuration is added by MyCustomPlugin compile configurations.webdriver // This configuration is added by MyCustomPlugin } repositories { maven { url = "${artifactory_contextUrl}/repo" } } publishing { publications { myPublicationName(MavenPublication) { artifactId 'lrgemaas_small_deploy_3n' artifact jar.archivePath } } repositories { maven { url = "${artifactory_contextUrl}/${artifactory_repoName}" credentials { username = "${artifactory_user}" password = "${artifactory_password}" } } } } // workflow for build defaultTasks 'clean','build','publish' 

PS: I tried to do nothing in the user plugin (i.e. just return from the apply method), but it still gives the same error.

+5
source share
4 answers

Just replace:

 publishing { publications { ... } } 

with the following:

 publishing.publications { ... } 

worked for me!

+32
source

Gradle is fragile regarding the order of plugins. This exact question is discussed in

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

"Cool, that's what happens.

The DefaultPublishingExtension supporting the publishing unit {} 'is DeferredConfigurable. This is a mechanism that allows you to register a configuration block that will be executed when accessing the extension. Unfortunately, sometimes this leads to unexpected behavior if you get access to this type of extension. This is exactly the case when, for example, you try to get all the project properties (as the release plugin does: https://github.com/townsfolk/gradle-release/blob/master/src/main/groovy/release/PluginHelper. groovy # L230 "

+1
source

FYI, I am using the dynamic version and found that I need to determine the version before applying my plugins. Probably because java or maven-publish sets the post details after the application.

+1
source

I upgraded the gradle version from version 2.1 to version 2.12 and solved this problem, fwiw.

0
source

Source: https://habr.com/ru/post/1211393/


All Articles