简体   繁体   English

Maven 带有自定义变量的工件版本号

[英]Maven artifact version number with custom variable

I have in my pom this section:我在我的 pom 这个部分:

<groupId>com.sample.app</groupId>
<artifactId>simpleapp</artifactId>
<version>1.0.9-${buildNumber}-SNAPSHOT</version>
<packaging>war</packaging>

Is there any nice and "maven way" to keep this variable name ${buildNumber} in that place in pom as this is now?有没有什么好的和“maven 方式”来保持这个变量名 ${buildNumber} 在 pom 中的那个地方,就像现在这样? I mean - when I am performing我的意思是——当我表演的时候

mvn deploy:prepare deploy:release  -DbuildNumber=${BUILD_NUMBER}

this version section in pom.xml is updated to (when BUILD_NUMBER eq: 12): pom.xml 中的此版本部分已更新为(当 BUILD_NUMBER eq: 12 时):

<version>1.0.9-12-SNAPSHOT</version>

which almost is ok but this is also commited to repository.这几乎可以,但这也已提交到存储库。 I like the fact that this tag: 1.0.9-12 in git repo is created, but I prefer to keep my original format of version in pom.xml file:我喜欢这样一个事实,即在 git 存储库中创建了这个标签:1.0.9-12,但我更喜欢在pom.xml文件中保留我的原始版本格式:

<version>1.0.9-${buildNumber}-SNAPSHOT</version>

This is because this stupid approach I have in my company to add to artefact version also build number from CI tool:(这是因为我在公司中添加到人工制品版本的这种愚蠢方法也来自 CI 工具的内部版本号:(

Can someone give me some hint how to handle this?有人可以给我一些提示如何处理吗?

The Maven Release Plugin has a parameter called developmentVersion that allows you to set the new version that is committed to your git branch after the release is done. Maven 发布插件有一个名为developmentVersion的参数,允许您设置发布完成后提交到 git 分支的新版本。

If you want to tell the Release Plugin to reuse the parts of version you used before, the Build Helper Maven Plugin helps you to parse the version.如果您想告诉 Release Plugin 重用您之前使用的版本部分, Build Helper Maven Plugin可以帮助您解析版本。 It creates properties like majorVersion and minorVersion from which you can construct the target version you like.它创建诸如majorVersionminorVersion之类的属性,您可以从中构造您喜欢的目标版本。

thanks JF Meier - I think that this will solve "my problem":感谢 JF Meier - 我认为这将解决“我的问题”:

mvn --batch-mode \
-DdevelopmentVersion=1.6.6-\${buildNumber}-SNAPSHOT \
-DreleaseVersion=1.6.6-18 \
release:clean \
release:prepare \
release:perform

I don't know how to use this plugin: build-helper:parse-version to obtain major,minor and incremental number but I will use some Jenkins plugin to extract those values from pom.xml.我不知道如何使用这个插件:build-helper:parse-version 来获取主要、次要和增量编号,但我将使用一些 Jenkins 插件从 pom.xml 中提取这些值。 Then I can set it dynamically, perform whole operation automatically (build + git tag + upload to nexus) and as a result my pom.xml will be updated with ${buildNumber} variable!然后我可以动态设置它,自动执行整个操作(构建 + git 标签 + 上传到 nexus),结果我的 pom.xml 将使用 ${buildNumber} 变量更新!

Thanks!谢谢!

UPDATE:更新:

I've added dependency for this helper plugin and final result is like this:我已经为这个助手插件添加了依赖,最终结果是这样的:

mvn --batch-mode \
build-helper:parse-version \
-DdevelopmentVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion}-\${parsedVersion.qualifier} \
-DreleaseVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.incrementalVersion}-31 \
release:clean \
release:prepare \
release:perform

I removed this ${buildNumber} as it is not required - Build Helper Plugin helped me a lot - I do not need any additional step in CI plan.我删除了这个 ${buildNumber} 因为它不是必需的 - Build Helper Plugin 帮助了我很多 - 我不需要 CI 计划中的任何额外步骤。 Now I have autoincrement and during release I am able to add build plan ID.现在我有了自动增量,并且在发布期间我可以添加构建计划 ID。

For me case solved:-)对我来说,情况已解决:-)

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

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