Maven 版本控制最佳实践 [英] Maven versioning best practices
问题描述
更改Maven项目版本的最佳方式是什么,发布此版本然后返回*-SNAPSHOT
开发.
What is the best way to change version of Maven project, to release this version and then return back to *-SNAPSHOT
development.
目前我正在做以下事情:
Currently I'm doing following:
- 从
pom.xml
检索当前版本(最有可能使用 - 增量版本(
mvn -DnewVersion=
),尊重问题中描述的规则Maven 补丁版本versions:set mvn:install
发送到仓库- 再次重命名版本,添加
SNAPSHOT
后缀. - 提交更改(使用一些版本控制系统)
SNAPSHOT
)- retrieve current version (most likely with
SNAPSHOT
) frompom.xml
- increment version (
mvn -DnewVersion=<something> versions:set
), respecting rules described in the question Maven artifact version for patches mvn:install
to sent to repo- renaming version once again adding
SNAPSHOT
postfix. - committing changes (using some version control system)
我有一种强烈的感觉,我做错了什么和/或效率低下.
I have a strong feeling I'm doing something wrong and/or inefficient.
推荐答案
你应该使用 maven-release-plugin 来发布你的工件.发布插件会自动增加您的所有版本.如果您从 1.0.3-SNAPSHOT 到 1.1.0-SNAPSHOT ,则可能是个例外.使用 Maven 进行开发的时间表是:
You should use the maven-release-plugin to release your artifacts. Than automatically all your versions will be incremented by the release-plugin. The exception might be if you are going from 1.0.3-SNAPSHOT to 1.1.0-SNAPSHOT . The timeline for developing with Maven is:
1.0.0-SNAPSHOT
1.0.0
1.0.1-SNAPSHOT
1.0.1
1.0.2-SNAPSHOT
1.0.2
..
要从 SNAPSHOT 到发布版本,您应该使用 maven 发布插件,您只需使用以下命令即可发布工件:
To go for the step from a SNAPSHOT to a release version you should use the maven release plugin you can release an artifact simply by using:
第一步:
mvn release:prepare
最后一步:
mvn release:perform
如果你想接受默认值,你可以简单地添加 -B 像:
If you would like to accept the defaults you can simply add -B like:
mvn -B release:prepare
或者您可以将这些步骤合并为一个:
or you can combine those steps into a single one:
mvn -B release:prepare release:perform
上述内容也可以在 CI 解决方案中使用.
The above can also be used from within a CI solution.
使用 mvn install 仅用于将工件安装到本地存储库中.如果您正在使用像存储库管理器这样的真实人(我可以推荐),您必须使用:
Using mvn install is only intended to install the artifacts into your local repository. If you are working with a real one like a repository manager (which i can recommend) you have to use:
mvn deploy
使用发布插件的一个要求是在你的 pom 中配置 scm 区域(我希望你使用的是版本控制?).
One requirement for using the release plugin is to configure the scm area in your pom (i hope you are using a version control?).
这篇关于Maven 版本控制最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!