gpt4 book ai didi

gradle - Gradle Maven-Publish插件不允许设置版本

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

我需要有关使用“maven-publish”插件发布 Artifact 的帮助。我使用它,因为下一步是发布项目的多个 Artifact ,并且在这种情况下几乎不可用的“maven”插件。因此,请不要建议使用它。如果我使用变量来设置版本,然后gradle失败,则会出现错误。如果我指定固定值,则工作正常,但是如果使用变量,则行不通。如何将版本从变量传递到出版物?

相关代码:

println "project.version = $project.version"
ext.artifactVersion = String.valueOf(project.version);

println "artifactVersion = $artifactVersion" // to check that value is correct

publishing {
publications {
//publishArtifact(project)
maven(MavenPublication) {
groupId project.group
artifactId project.ext.artifactId

println artifactVersion
String artifactVersion2 = artifactVersion
//version "1248" // works
//version artifactVersion // doesn't work
//version "$artifactVersion" // doesn't work
//version ''+artifactVersion // doesn't work
//version '1248' // works
//version
version "${artifactVersion}" // doesn't work
from project.components.java
}
}
}

输出:
project.version = 1248
artifactVersion = 1248
1248
:prj:generatePomFileForMavenPublication
:prj:compileJava UP-TO-DATE
:prj:processResources UP-TO-DATE
:prj:classes UP-TO-DATE
:prj:jar UP-TO-DATE
:prj:publishMavenPublicationToMavenLocal FAILED
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':prj:publishMavenPublicationToMavenLocal'.
> Failed to publish publication 'maven' to repository 'MavenLocal'
> Invalid publication 'maven': supplied version does not match POM file (cannot edit version directly in the POM file).

最佳答案

谢谢大家调查问题。我发现了问题,并在此处发布了结果,希望对您有所帮助。
版本不能包含空格的问题的原因。在我的情况下,版本包含尾部空间,但我没有注意到。看起来Gradle修剪了从生成的pom中读取值的值,然后对其进行比较以检查值是否已更改。希望这可以帮助某人节省时间。

ext.artifactVersion = String.valueOf(project.version).trim();

关于gradle - Gradle Maven-Publish插件不允许设置版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27150178/

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