简体   繁体   English

如何防止在maven-release-plugin中推送SNAPSHOT版本?

[英]How to prevent pushing SNAPSHOT version in maven-release-plugin?

I have a maven project with lots of modules (and modules inside modules). 我有一个包含大量模块的maven项目(以及模块内的模块)。 I am using maven-release-plugin for controlling the versions in the pom.xml files. 我正在使用maven-release-plugin来控制pom.xml文件中的版本。

When running command mvn release:prepare plugin is pushing two commits with messages: "[maven-release-plugin] prepare release v0.9.0.38" and "[maven-release-plugin] prepare for next development iteration" accordingly. 当运行命令mvn release:prepare plugin正在推送两个提交消息: “[maven-release-plugin] prepare release v0.9.0.38”“[maven-release-plugin]准备下一次开发迭代” Herein the second one is just snapshot version. 这里第二个只是快照版本。

Here is the maven-release-plugin settings: 这是maven-release-plugin设置:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.3</version>

            <configuration>
                <tagNameFormat>v@{project.version}</tagNameFormat>
                <autoVersionSubmodules>true</autoVersionSubmodules>
                <checkModificationExcludes>
                    <checkModificationExclude>pom.xml</checkModificationExclude>
                    <checkModificationExclude>*/pom.xml</checkModificationExclude>
                </checkModificationExcludes>
                <branchBase>master</branchBase>
            </configuration>
        </plugin>
    </plugins>
</build>

When pushing I am setting the tag to the remote git project as well (You can see it in <tagNameFormat>v@{project.version}</tagNameFormat> ) so I need to push commits definitely, but I don't want it to push snapshot versions (eg 0.9.0.38-SNAPSHOT). 推送时我也将标签设置为远程git项目(你可以在<tagNameFormat>v@{project.version}</tagNameFormat>看到它)所以我需要明确推送提交,但我不想要它推送快照版本(例如0.9.0.38-SNAPSHOT)。

Edit: 编辑:

The problem: 问题:

As I am incrementing minor version of the project on each commit by running 因为我通过运行在每次提交时递增项目的次要版本
mvn release:prepare . mvn release:prepare
eg Commits looks like following: 例如,Commits看起来如下:

[maven-release-plugin] prepare for next development iteration [maven-release-plugin]为下一次开发迭代做准备
[maven-release-plugin] prepare release v0.9.0.38 [maven-release-plugin]准备发布v0.9.0.38
(refactor) Code cleaned up (重构)代码清理完毕
[maven-release-plugin] prepare for next development iteration [maven-release-plugin]为下一次开发迭代做准备
[maven-release-plugin] prepare release v0.9.0.37 [maven-release-plugin]准备发布v0.9.0.37
(feature) Added I18N support (功能)添加了I18N支持

This looks very ugly, and pushing three commits on every change is very bad solution only for just incrementing minor version of the pom file not manually. 这看起来非常难看,并且在每次更改时推送三次提交都是非常糟糕的解决方案,仅用于仅手动递增次要版本的pom文件。

What do I need? 我需要什么?

  • Before every commit increment project version (including all modules) 在每个提交增量项目版本之前(包括所有模块)
  • And set the tag to the remote git repository. 并将标记设置为远程git存储库。
  • And it should be done by one commit with custom message 它应该通过一个提交自定义消息来完成

How can I achieve this? 我怎样才能做到这一点?

Described behavior is intended - plugin increments version of your modules after releasing them which is normal. 所描述的行为是预期的 - 插件在发布后增加模块的版本,这是正常的。 So the main advice is think twice before customizing it. 因此,主要建议是在定制之前再三考虑。

If you're using Git, you can set pushChanges to false to avoid pushing. 如果你正在使用Git,你可以将pushChanges设置为false以避免推送。 After that you can rollback last commit and push changes 之后,您可以回滚上次提交并推送更改

git reset HEAD~ --hard
git push origin master

Advice would be more practical if you explained why you consider the second commit as redundant. 如果你解释为什么你认为第二次提交是多余的,那么建议会更实用。

Also you always can use dryRun switch if you're not sure about changes. 如果您不确定更改,也可以使用dryRun开关。

Update: 更新:

  1. Do your changes 做你的改变
  2. mvn versions:set -DnewVersion=<version-to-set> -DgenerateBackupPoms=false
  3. git commit -m "your-comment"
  4. git tag <your-tag>
  5. Push commit/tag 推送提交/标记

These steps can be easily aggregated to script file to avoid monkey-job. 这些步骤可以很容易地聚合到脚本文件,以避免猴子的工作。

As an alternative, you can look to BuildNumber-maven-plugin , which also can be useful. 作为替代方案,您可以查看BuildNumber-maven-plugin ,它也很有用。

To just update versions you can use release:update-versions and then commit manually. 要更新版本,您可以使用release:update-versions ,然后手动提交。

The documentation also lists the suppressCommitBeforeTag option for release:prepare , which sounds like it should prevent committing. 文档还列出了release:preparesuppressCommitBeforeTag选项,听起来应该阻止提交。

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

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