【maven】versions-maven-plugin 使用

一句话概括,这个插件是用来修改pom的版本的,几乎是所有的版本号,比如工程,依赖和插件等等。

那么这个插件有什么用?

之前介绍过maven的版本管理经验,所有依赖都有一个root-pom来统一管理。

这样的话,每发一个release的包,其实就应该同时也修改了root-pom中这个包的版本号,这样,其他工程才能依赖到最新的代码。那么修改root-pom版本号的任务就可以交给versions插件。

这个可以放在jenkins中作为一个post-action来处理。每构建一个release包就触发一次root-pom修改。

 

下面介绍下常用命令:
1. 修改本工程的版本号:

mvn versions:set -DnewVersion=xxx

2. 回滚:

versions的任何目标,最终都会先记录一个pom.xml.versionsBackup文件暂存改动,可以使用

mvn versions:revert来回滚,这样就会恢复成pom.xml.versionsBackup文件的样子同时删除pom.xml.versionsBackup。

当然也可以mvn versions:commit来提交修改,删除pom.xml.versionsBackup文件。

3. 修改依赖的版本:

  • versions:use-next-releases searches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the next release version.
  • versions:use-latest-releases searches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the latest release version.
  • versions:use-next-snapshots searches the pom for all non-SNAPSHOT versions which have been a newer -SNAPSHOT version and replaces them with the next -SNAPSHOT version.
  • versions:use-latest-snapshots searches the pom for all non-SNAPSHOT versions which have been a newer -SNAPSHOT version and replaces them with the latest -SNAPSHOT version.
  • versions:use-next-versions searches the pom for all versions which have been a newer version and replaces them with the next version.
  • versions:use-latest-versions searches the pom for all versions which have been a newer version and replaces them with the latest version.

其实主要就这六个。前四个只会修改pom中的release依赖版本号,修改为下一个release或者snapshot。后两个会修改所有的依赖为下一个或者最新的版本号。

注意2.0版本的下一个snapshot为2.1-SNAPSHOT而非3.0-SNAPSHOT。

当然可以指定修改特定的依赖的版本号,通过添加-Dincludes=group:artifact即可,并且支持通配符。

另外,默认会修改dependency和dependencyMangement的版本号,可以加参数限定:

mvn versions:use-next-releases -DprocessDependencies=false
mvn versions:use-next-releases -DprocessDependencyManagement=false

 

参考至:http://www.mojohaus.org/versions-maven-plugin/examples/advancing-dependency-versions.html

 

 

 

--------------------------------------------------------------

补充:

还有一个很有用的点,可以使用set-property目标来修改pom中定义的property。这个在修改root-pom中的依赖版本会很有用。因为一般root-pom中的依赖的版本都是通过property来定义的,这样通过修改property就能修改依赖版本了,更新一个工程之后修改root-pom会很有用。

例子:

      <dependency>
          <groupId>com.liyao</groupId>
          <artifactId>libJar</artifactId>
          <version>${lib.version}</version>
      </dependency>
      <lib.version>1.0-SNAPSHOT</lib.version>

 mvn versions:set-property -Dproperty=lib.version -DnewVersion=1.1-SNAPSHOT
 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值