简体   繁体   English

在 mvn 发布期间使用 mvn 版本插件

[英]Use mvn version plugin during mvn release

I have a multi-module maven project in Kubernates.我在 Kubernates 有一个多模块 maven 项目。 We intend to version all these modules together.我们打算一起对所有这些模块进行版本控制。 But as of now, I end up hard-coding version in each of the module pom.xml as below但截至目前,我最终在每个模块 pom.xml 中的硬编码版本如下

<parent>
    <artifactId>xyz-application</artifactId>
    <groupId>com.xyz</groupId>
    <version>2.50.0.g</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>xyz-Library</artifactId>
<version>2.50.0.g</version>

The main parent module has the below configuration主父模块具有以下配置

<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>xyz-application</artifactId>
<version>2.50.0.g</version>
<packaging>pom</packaging>

Reference 参考

Currently, I'm using the mvn release plugin in the pom.xml目前,我在 pom.xml 中使用 mvn 发布插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.5.3</version>
    <configuration>
        <autoVersionSubmodules>true</autoVersionSubmodules>
        <tagNameFormat>${product_label}-@{project.version}</tagNameFormat>
        <releaseProfiles>releases</releaseProfiles>
        <preparationGoals>clean deploy</preparationGoals>
        <arguments>-s settings.xml</arguments> 
    </configuration>
</plugin>

Since the project is in Kubernetes, here is the Jenkins file content I'm using while the release由于项目在 Kubernetes,这里是我在发布时使用的 Jenkins 文件内容

def MVN_RELEASE = "release:clean release:prepare release:perform -Dmaven.source.skip=true"
stage('Release artifacts to artifactory') {
    steps {
        container('maven') {
            withCredentials() {
                sh "mvn ${MVN_RELEASE}  -Dresume=false"
            }
        }
    }
}

Now, during release, I need to update the parent pom and all sub-modules poms version by a new version of my choice, I can use a mvn version plugin , something like现在,在发布期间,我需要通过我选择的新版本更新父 pom 和所有子模块 pom 版本,我可以使用mvn 版本插件,例如

  1. mvn versions:set -DnewVersion=3.00.0-SNAPSHOT -DprocessAllModules -DgenerateBackupPoms=false and then mvn versions:set -DnewVersion=3.00.0-SNAPSHOT -DprocessAllModules -DgenerateBackupPoms=false然后
  2. mvn versions:commit -DprocessAllModules

At what stage in Jenkins/pom.xml should I add this?我应该在 Jenkins/pom.xml 的哪个阶段添加这个? Now, this plugin is useful only when I want to bump to a specific version of my choice (like 3.00.0-Snapshot ), otherwise, the mvn release plugin should bump the version automatically to something like 2.50.1-SNAPSHOT .现在,这个插件只有在我想升级到我选择的特定版本(比如3.00.0-Snapshot )时才有用,否则,mvn release 插件应该自动将版本升级到2.50.1-SNAPSHOT之类的东西。 Is that correct understanding?这是正确的理解吗?

How can I gracefully handle this pom version update issue?如何优雅地处理这个 pom 版本更新问题?

Thanks in advance!提前致谢!

I do not see why you want the version plugin.我不明白你为什么想要版本插件。

First of all, you don't need to add the <version> tag to the modules.首先,您不需要将<version>标记添加到模块中。 You need to specify the version of the parent, but you can inherit your version (which is the same) from the parent.您需要指定父级的版本,但您可以从父级继承您的版本(相同)。

Secondly, the maven release plugin has parameters releaseVersion and developmentVersion which allow you to set a release and future development version on the command line.其次,maven 发布插件具有参数releaseVersiondevelopmentVersion允许您在命令行上设置发布和未来开发版本。

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

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