gpt4 book ai didi

gradle - Gradle将发布从Gradle 4.x迁移到5.x?

转载 作者:行者123 更新时间:2023-12-03 04:15:44 27 4
gpt4 key购买 nike

如何将以下发布从Gradle 4迁移到5?

publishing {
publications {
foo(MavenPublication) {
artifactId "foo"
artifact jar

pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', 'mygroup')
dependencyNode.appendNode('artifactId', 'bar')
dependencyNode.appendNode('version', '1.0')

}
}
}
}

这适用于gradle 4.5.1。但是对于gradle 5.4.1,错误:
Execution failed for task ':publishFooPublicationToMavenLocal'.
> Failed to publish publication 'foo' to repository 'mavenLocal'
> Invalid publication 'foo': artifactId is not a valid Maven identifier ([A-Za-z0-9_\-.]+).

最佳答案

使用gradle 4.8+,您必须将publishing{}块包含在project.afterEvaluate

project.afterEvaluate {
publishing {
publications {
foo(MavenPublication) {
artifactId "foo"
artifact jar

pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', 'mygroup')
dependencyNode.appendNode('artifactId', 'bar')
dependencyNode.appendNode('version', '1.0')

}
}

}
}

您可以找到 official doc here:

Prior to Gradle 4.8, the publishing {} block was implicitly treated as if all the logic inside it was executed after the project was evaluated. This was confusing, because it was the only block that behaved that way. As part of the stabilization effort in Gradle 4.8, we are deprecating this behavior and asking all users to migrate their build.

关于gradle - Gradle将发布从Gradle 4.x迁移到5.x?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56310635/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com