我需要使用“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).