我需要帮助使用'maven-publish'插件发布工件。我使用它,因为我的下一步是发布项目的几个工件和'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).
答案 0 :(得分:2)
感谢所有人研究问题。我找到了问题,并在此处发布结果,希望它能帮到某人。 版本不能包含空格的问题的原因。在我的情况下,版本包含我没有注意到的尾随空格。它看起来像Gradle修剪从生成的pom读取它的值,然后比较它以检查值是否更改。希望这有助于节省时间。
ext.artifactVersion = String.valueOf(project.version).trim();