Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义gradle插件原因:无法配置';出版';延伸_Gradle_Build.gradle - Fatal编程技术网

自定义gradle插件原因:无法配置';出版';延伸

自定义gradle插件原因:无法配置';出版';延伸,gradle,build.gradle,Gradle,Build.gradle,我有一个自定义gradle插件,其中添加了自定义任务类型和gradle配置。当我在maven publish之前应用这个插件时,它工作得非常好。但当我在应用插件:“maven publish”之后添加它时,它失败并显示错误消息: FAILURE: Build failed with an exception. * Where: Build file '/scratch/skgupta/git_storage/emdi/integtest/build.gradle' line: 38 * Wh

我有一个自定义gradle插件,其中添加了自定义任务类型和gradle配置。当我在
maven publish
之前应用这个插件时,它工作得非常好。但当我在应用插件:“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
这是
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方法返回),但它仍然给出相同的错误。

Gradle对于插件的顺序很脆弱。关于这个确切的问题,目前正在进行讨论

“酷,就是这样

支持“发布{}”的DefaultPublishingExtension'块是延迟可配置的。它是一种机制,允许在访问扩展时注册要执行的配置块。不幸的是,如果您无意中访问此类扩展,有时会导致意外行为。例如,当您尝试获取项目的所有属性时,正是这种情况(正如发布插件在此处所做的那样:

简单地替换:

publishing {
    publications {
      ...
  }
}
包括:

publishing.publications {
  ...
}

为我工作!

我将gradle版本从2.1升级到2.12,解决了这个问题,fwiw。

仅供参考,我使用了动态版本,发现我必须在应用插件之前定义版本。可能是因为java或maven publish在应用时设置了发布细节。

这看起来与此相关:我们切换到了Android Studio 2.1并开始将volley作为子模块添加时出现此问题。此解决方案对我们有效。奇怪的是……这也为我解决了此问题。其他人建议交换插件声明顺序,但这对我的情况没有帮助。对gradlew 2.13有经验的人对修复感兴趣,请参阅