自定义gradle插件原因:无法配置"发布"扩展

Sun*_*pta 8 gradle build.gradle

我有一个自定义gradle插件,其中添加了自定义任务类型和gradle配置.当我应用这个插件之前maven-publish它完全正常.但是当我在之后添加它时apply plugin: 'maven-publish',它会失败并显示错误消息:

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
Run Code Online (Sandbox Code Playgroud)

这是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'
Run Code Online (Sandbox Code Playgroud)

PS:我尝试在自定义插件中什么都不做(即,只需从apply方法返回),但它仍然会出现同样的错误.

Vin*_*nay 38

简单地替换:

publishing {
    publications {
      ...
  }
}
Run Code Online (Sandbox Code Playgroud)

以下内容:

publishing.publications {
  ...
}
Run Code Online (Sandbox Code Playgroud)

为我工作!

  • 奇怪......这也为我解决了.其他人建议交换插件声明顺序,但这对我的情况没有帮助.有经验的gradlew 2.13 (3认同)