如何在Maven versions:set中忽略SNAPSHOT版本?

huangapple go评论58阅读模式
英文:

How to ignore SNAPSHOTs on Maven versions:set?

问题

I would like to have Maven build Java projects on our Jenkins server. The version should be set correctly in the pom.xml. For this I use in the PreBuild Step:

mvn build-helper:parse-version versions:set -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${parsedVersion.qualifier?}.##JenkinsBuildNumber##

0.3.12
0.5.56 etc.

It will now build the version correctly.

But now I notice that from SNAPSHOTs now also normal versions are built:

1.0-SNAPSHOT => 1.0.12
2.0-SNAPSHOT => 2.0.54

Of course this should not be. Best no version is to be adapted with SNAPSHOTS at all, thus Ignoriert. But this does not work:

mvn build-helper:parse-version versions:set -DignoredVersions=.*-SNAPSHOT -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${parsedVersion.qualifier?}.##JenkinsBuildNumber##

The build number is still appended. How can I get versions:set to not change the version on SNAPSHOTs?

1.0-SNAPSHOT => 1.0-SNAPSHOT
2.0-SNAPSHOT => 2.0-SNAPSHOT
0.3.0 => 0.3.12
0.5.0 => 0.5.56
1.2.0 => 1.2.124

英文:

I would like to have Maven build Java projects on our Jenkins server. The version should be set correctly in the pom.xml. For this I use in the PreBuild Step:

mvn build-helper:parse-version versions:set -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${parsedVersion.qualifier?}.##JenkinsBuildNumber##

0.3.12
0.5.56 etc.

It will now build the version correctly.

But now I notice that from SNAPSHOTs now also normal versions are built:

1.0-SNAPSHOT => 1.0.12
2.0-SNAPSHOT => 2.0.54

Of course this should not be. Best no version is to be adapted with SNAPSHOTS at all, thus Ignoriert. But this does not work:

mvn build-helper:parse-version versions:set -DignoredVersions=.*-SNAPSHOT -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${parsedVersion.qualifier?}.##JenkinsBuildNumber##

The build number is still appended. How can I get versions:set to not change the version on SNAPSHOTs?

1.0-SNAPSHOT => 1.0-SNAPSHOT
2.0-SNAPSHOT => 2.0-SNAPSHOT
0.3.0 => 0.3.12
0.5.0 => 0.5.56
1.2.0 => 1.2.124

答案1

得分: 2

我用一个预构建步骤解决了它

条件步骤
执行 Shell
ACTUALVERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) && if echo ${ACTUALVERSION} | test=$(grep -v "SNAPSHOT"); then exit 0; else exit 1; fi

运行 Maven 目标

build-helper:parse-version versions:set -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${parsedVersion.qualifier?}.${BUILD_NUMBER}
英文:

I solved it with a Pre-Build Step

Conditional Step
Execute Shell
ACTUALVERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) && if echo ${ACTUALVERSION} | test=$(grep -v "SNAPSHOT"); then exit 0; else exit 1; fi

Run Maven Goal

build-helper:parse-version versions:set -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${parsedVersion.qualifier?}.${BUILD_NUMBER}

huangapple
  • 本文由 发表于 2023年6月27日 17:06:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76563293.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定