问题描述
更改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=<something> versions:set
),遵守问题>修补程序的Maven工件版本中描述的规则 -
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版本控制最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!