简体   繁体   English

Maven,删除部分版本并替换为内部版本号

[英]Maven, remove part of version and replace with build number

In my pom.xml the version is 1.0-SNAPSHOT. 在我的pom.xml中,版本是1.0-SNAPSHOT。 I'm using bamboo to deploy the snapshot to nexus using: 我正在使用bamboo将快照部署到nexus:

mvn clean deploy 

The problem is that I want the project version to appear in nexus as 1.0-22 (The build number, 22 is just an example) and not 1.0-SNAPSHOT. 问题是我希望项目版本在nexus中显示为1.0-22(内部版本号,22只是一个示例)而不是1.0-SNAPSHOT。

I know in bamboo I can use: 我知道在竹子里我可以使用:

mvn versions:set -DnewVersion=1.0-${build.buildNumber}
mvn clean deploy
mvn versions:revert

The problem is I don't want to hard code 1.0 into all my bamboo builds because that part might change in the future and if it does I don't want to go into bamboo to change it. 问题是我不想硬编码1.0进入我的所有竹子版本,因为这部分可能会在未来发生变化,如果确实如此,我不想进入竹子来改变它。 Also, I need the version to stay as 1.0-SNAPSHOT in the pom.xml because it's deploying to other places and not just nexus. 另外,我需要将版本保留为pom.xml中的1.0-SNAPSHOT,因为它正在部署到其他地方,而不仅仅是nexus。 Is there a way to change part of a version number using a command? 有没有办法使用命令更改部分版本号? ie removing the -SNAPSHOT part and replacing it with the build number and then reverting back to the old snapshot version when deploying elsewhere. 即删除-SNAPSHOT部分并将其替换为内部版本号,然后在其他地方部署时恢复为旧的快照版本。

If you're running on a Unix based system you could try: 如果您在基于Unix的系统上运行,您可以尝试:

BASE_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep SNAPSHOT | grep -v INFO | sed 's/-SNAPSHOT//g')
mvn versions:set -DnewVersion=$BASE_VERSION-${build.buildNumber}
mvn clean deploy
mvn versions:revert

You may need to adjust the BASE_VERSION string as I'm not 100% sure how it may function on a multi-pom project. 您可能需要调整BASE_VERSION字符串,因为我不能100%确定它如何在多pom项目上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM