我有一个定制的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这是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方法返回),但是它仍然给出了相同的错误。
发布于 2016-04-19 13:43:24
简单地替换:
publishing {
publications {
...
}
}包括以下内容:
publishing.publications {
...
}为我工作!
发布于 2015-07-06 23:22:59
关于插件的顺序,Gradle很脆弱。关于这个确切的问题,在
https://discuss.gradle.org/t/apply-maven-publish-plugin-from-init-script/2460
“太酷了,这就是发生的事。 支持“发布{}”块的DefaultPublishingExtension是一个DeferredConfigurable。它是一种机制,允许在访问扩展时注册要执行的配置块。不幸的是,如果您无意中访问这种扩展,有时会导致意外行为。例如,当您尝试获取项目的所有属性(正如发布插件在这里所做的:https://github.com/townsfolk/gradle-release/blob/master/src/main/groovy/release/PluginHelper.groovy#L230)时,情况就是如此。
发布于 2017-06-20 17:03:56
FYI,我使用一个动态版本,发现我必须在应用插件之前定义版本。可能是因为java或maven发布在应用程序上设置了发布细节。
https://stackoverflow.com/questions/28020520
复制相似问题