自定义gradle插件原因:无法配置“发布”扩展名 [英] custom gradle plugin causes: Cannot configure the 'publishing' extension

查看:217
本文介绍了自定义gradle插件原因:无法配置“发布”扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义gradle插件,其中添加了自定义任务类型和gradle配置。当我在 maven-publish 之前应用此插件时,它工作得很好。但是当我在 apply plugin:'maven-publish'之后添加它时,它失败并显示错误消息:

I have a custom gradle plugin in which custom task types and gradle configurations are added. When I apply this plugin before maven-publish it works perfectly fine. But when I add it after apply plugin: 'maven-publish', it fails with 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

这是 build.gradle 文件。

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:我尝试在自定义插件中不执行任何操作(即,仅从apply方法返回),但仍然会出现相同的错误。

PS: I tried doing nothing in the custom plugin (i.e., simply return from apply method), but it still gives same error.

推荐答案

只需替换:

publishing {
    publications {
      ...
  }
}

具有以下内容:

publishing.publications {
  ...
}

为我工作!

这篇关于自定义gradle插件原因:无法配置“发布”扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆