文档章节

maven 的版本升级,切换

洞渊龙王
 洞渊龙王
发布于 2017/05/10 17:39
字数 2104
阅读 485
收藏 0

#maven 的版本升级,切换

[toc]

  1. 首先描述一下项目的pom的版本 父pom
<groupId>com.dxhy.jdService</groupId>
<artifactId>insert-card</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

某子pom

<parent>
    <artifactId>insert-card</artifactId>
    <groupId>com.dxhy.jdService</groupId>
    <version>1.0.0-SNAPSHOT</version>
</parent>

使用案例

案例描述

使用场景:

在版本控制中准备将测试成功的分支合并到master分支中,将快照版本替换为正式版本。发布正式版本。 然后将版本升级为下一个小版本。提交到开发者分支。发布新版本的开发版本。

使用需求点:

  1. 父子pom中版本的修改
  2. 配置文件中对子版本的互相调用的版本修改。

一、发布正式版本

1. 将原来 1.0.0-SNAPSHOT 升级为 1.0.0正式版本

mvn versions:set -DnewVersion=1.0.0 -DallowSnopShot=true

-DnewVersion=1.0.0 为设定新版本 -DallowSnopShot=true 为运行快照版本执行

2. 执行提交命令

mvn versions:commit

3. 执行修改pom文件中某properties 的版本号

mvn versions:update-properties -DallowSnatshots=true -Dincludes=com.dxhy.jdService:*

-DallowSnopShot=true 为运行快照版本执行

-Dincludes=com.dxhy.jdService:* 为只允许groupId为com.dxhy.jdService的jar使用的配置文件更改。

4. 执行提交命令

mvn versions:commit

二、升级为高版本快照版本

1. 将原来 1.0.0-SNAPSHOT 升级为 1.0.1-SNAPSHOT

mvn versions:set -DnewVersion=1.0.1-SNAPSHOT

因为当前版本为正式版本,所以不用写运行快照版本也行;

2. 执行提交命令

mvn versions:commit

3. 执行修改pom文件中某properties 的版本号

mvn versions:update-properties -DallowSnatshots=true -Dincludes=com.dxhy.jdService:*

4. 执行提交命令

mvn versions:commit

备份:

1. 执行提交命令过程

赵睿@zhaorui MINGW64 /d/workspace/com/dxhy/jdService/insert-card (master)
$ mvn versions:commit
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] insert-card
[INFO] insert-card-core
[INFO] insert-card-accepter
[INFO] insert-card-processer
[INFO] insert-card-sender
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:commit (default-cli) @ insert-card ---
[INFO] Accepting all changes to D:\workspace\com\dxhy\jdService\insert-card\pom.xml
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card-core 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:commit (default-cli) @ insert-card-core ---
[INFO] Accepting all changes to D:\workspace\com\dxhy\jdService\insert-card\insert-card-core\pom.xml
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card-accepter 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:commit (default-cli) @ insert-card-accepter ---
[INFO] Accepting all changes to D:\workspace\com\dxhy\jdService\insert-card\insert-card-accepter\pom.xml
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card-processer 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:commit (default-cli) @ insert-card-processer ---
[INFO] Accepting all changes to D:\workspace\com\dxhy\jdService\insert-card\insert-card-processer\pom.xml
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card-sender 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:commit (default-cli) @ insert-card-sender ---
[INFO] Accepting all changes to D:\workspace\com\dxhy\jdService\insert-card\insert-card-sender\pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] insert-card ........................................ SUCCESS [  1.728 s]
[INFO] insert-card-core ................................... SUCCESS [  0.004 s]
[INFO] insert-card-accepter ............................... SUCCESS [  0.003 s]
[INFO] insert-card-processer .............................. SUCCESS [  0.004 s]
[INFO] insert-card-sender ................................. SUCCESS [  0.012 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.194 s
[INFO] Finished at: 2017-05-10T15:28:56+08:00
[INFO] Final Memory: 19M/227M
[INFO] ------------------------------------------------------------------------

2. 执行修改版本的命令过程

赵睿@zhaorui MINGW64 /d/workspace/com/dxhy/jdService/insert-card (master)
$ mvn versions:set -DnewVersion=1.0.0 -DallowSnopShot=true
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] insert-card
[INFO] insert-card-core
[INFO] insert-card-accepter
[INFO] insert-card-processer
[INFO] insert-card-sender
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:set (default-cli) @ insert-card ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: D:\workspace\com\dxhy\jdService\insert-card
[INFO] Processing change of com.dxhy.jdService:insert-card:1.0.0-SNAPSHOT -> 1.0.0
[INFO] Processing com.dxhy.jdService:insert-card
[INFO]     Updating project com.dxhy.jdService:insert-card
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]
[INFO] Processing com.dxhy.jdService:insert-card-accepter
[INFO]     Updating parent com.dxhy.jdService:insert-card
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]
[INFO] Processing com.dxhy.jdService:insert-card-core
[INFO]     Updating parent com.dxhy.jdService:insert-card
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]
[INFO] Processing com.dxhy.jdService:insert-card-processer
[INFO]     Updating parent com.dxhy.jdService:insert-card
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]
[INFO] Processing com.dxhy.jdService:insert-card-sender
[INFO]     Updating parent com.dxhy.jdService:insert-card
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] insert-card ........................................ SUCCESS [  1.302 s]
[INFO] insert-card-core ................................... SKIPPED
[INFO] insert-card-accepter ............................... SKIPPED
[INFO] insert-card-processer .............................. SKIPPED
[INFO] insert-card-sender ................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.115 s
[INFO] Finished at: 2017-05-10T15:26:37+08:00
[INFO] Final Memory: 20M/227M
[INFO] -----------------------------------------------

3. 执行更改配置文件的命令过程

赵睿@zhaorui MINGW64 /d/workspace/com/dxhy/jdService/insert-card (master)
$ mvn versions:update-properties -DallowSnatshots=true -Dincludes=com.dxhy.jdService:*
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] insert-card
[INFO] insert-card-core
[INFO] insert-card-accepter
[INFO] insert-card-processer
[INFO] insert-card-sender
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:update-properties (default-cli) @ insert-card ---
[INFO] Not updating the property ${cxf.version} because it is used by artifact org.apache.cxf:cxf-rt-frontend-jaxws:jar:3.0.2 and that artifact is not included in the list of  allowed artifacts to be updated.
[INFO] Not updating the property ${mybatis.spring.boot.vesion} because it is used by artifact org.mybatis.spring.boot:mybatis-spring-boot-starter:jar:1.1.1 and that artifact is not included in the list of  allowed artifacts to be updated.
[INFO] Not updating the property ${commons.lang.version} because it is used by artifact commons-lang:commons-lang:jar:2.6 and that artifact is not included in the list of  allowed artifacts to be updated.
[INFO] Not updating the property ${commons.lang3.version} because it is used by artifact org.apache.commons:commons-lang3:jar:3.3.2 and that artifact is not included in the list of  allowed artifacts to be updated.
[INFO] Not updating the property ${druid.version} because it is used by artifact com.alibaba:druid:jar:1.0.29 and that artifact is not included in the list of  allowed artifacts to be updated.
[INFO] Not updating the property ${commons.io.version} because it is used by artifact commons-io:commons-io:jar:2.5 and that artifact is not included in the list of  allowed artifacts to be updated.
[INFO] Not updating the property ${tomcat.version} because it is used by artifact org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:7.0.77 and that artifact is not included in the list of  allowed artifacts to be updated.
[INFO] Updated ${project.version} from 1.0.0-SNAPSHOT to 1.0.0
[INFO] Not updating the property ${mysql.version} because it is used by artifact mysql:mysql-connector-java:jar:5.1.39 and that artifact is not included in the list of  allowed artifacts to be updated.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card-core 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:update-properties (default-cli) @ insert-card-core ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card-accepter 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:update-properties (default-cli) @ insert-card-accepter ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card-processer 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:update-properties (default-cli) @ insert-card-processer ---
[INFO] Not updating the property ${openApi.sdk.version} because it is used by artifact com.dxhy.openApi:openApi-sdk:jar:0.0.2-SNAPSHOT and that artifact is not included in the list of  allowed artifacts to be updated.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card-sender 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:update-properties (default-cli) @ insert-card-sender ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] insert-card ........................................ SUCCESS [  1.310 s]
[INFO] insert-card-core ................................... SUCCESS [  0.005 s]
[INFO] insert-card-accepter ............................... SUCCESS [  0.008 s]
[INFO] insert-card-processer .............................. SUCCESS [  0.016 s]
[INFO] insert-card-sender ................................. SUCCESS [  0.004 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.132 s
[INFO] Finished at: 2017-05-10T16:04:09+08:00
[INFO] Final Memory: 20M/227M
[INFO] ------------------------------------------------------------------------

Versions Maven Plugin 官方的一些插件介绍

Note: The first time any of the goals that modify the pom.xml file run, they will create a local backup copy pom.xml.versionsBackup. Subsequent modifications will leave this backup unchanged. The versions:commit goal will remove the backup copy, while the versions:revert goal will restore the backup copy. It is best practice to use a Source Code Management system and not rely on the pom.xml.versionsBackup files created by the versions-maven-plugin. The versions:commit and versions:revert goals are only a "Poor Man's SCM".

注意:首先任何修改pom.xml的指令执行,都创建一个本地备份的pom.xml.versionsBackup文件。随后的修改不会让这个备份被修改。

versions:commit 命令 会删除备份副本文件。

versions:revert 命令 会回复副本备份文件。

然后就是说最好是直接用scm直接源代码管理系统进行操作,而不是依靠通过versions-maven-plugin这个插件操作pom.xml.versionsBackup文件;versions:commitversions:revert恢复目标只是一个“匮乏的SCM”

versions:update-parent 升级父pom的包

执行命令之后,结果把我导入的spring-boot-starter-parent的版本升级了。

其他子命令:

mvn versions:update-parent "-DparentVersion=[14,16) 限定升级版本为14-16:

mvn versions:update-parent -DallowSnapshots=true

强制快照版本也可以升级

versions:revert 恢复上一个版本

versions:update-child-modules

mvn -N versions:update-child-modules

如果是快照,改不动,需要设定允许快照

mvn versions:update-child-modules  -DallowSnapshots=true

子版本会跟随父版本全部变化。

赵睿@zhaorui MINGW64 /d/workspace/com/dxhy/jdService/insert-card (release)
$ mvn -N versions:update-child-modules -DallowSnapshots=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building insert-card 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:update-child-modules (default-cli) @ insert-card ---
[INFO] Module: insert-card-accepter
[INFO]     parent was com.dxhy.jdService:insert-card:1.0.0
[INFO]     updated to com.dxhy.jdService:insert-card:1.0.0-SNAPSHOT
[INFO] Module: insert-card-core
[INFO]     parent was com.dxhy.jdService:insert-card:1.0.0
[INFO]     updated to com.dxhy.jdService:insert-card:1.0.0-SNAPSHOT
[INFO] Module: insert-card-processer
[INFO]     parent was com.dxhy.jdService:insert-card:1.0.0
[INFO]     updated to com.dxhy.jdService:insert-card:1.0.0-SNAPSHOT
[INFO] Module: insert-card-sender
[INFO]     parent was com.dxhy.jdService:insert-card:1.0.0
[INFO]     updated to com.dxhy.jdService:insert-card:1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.100 s
[INFO] Finished at: 2017-05-10T14:51:12+08:00
[INFO] Final Memory: 15M/155M
[INFO] ------------------------------------------------------------------------

versions:display-dependency-updates

可以查看jar包版本是不是最新的,是不是很牛逼啊

部分信息为:

[INFO]                                           1.1.2.RELEASE -> 1.2.0.RELEASE
[INFO]   org.springframework.restdocs:spring-restdocs-restassured ...
[INFO]                                           1.1.2.RELEASE -> 1.2.0.RELEASE
[INFO]   org.springframework.security.oauth:spring-security-oauth ...
[INFO]                                          2.0.13.RELEASE -> 2.1.0.RELEASE
[INFO]   org.springframework.security.oauth:spring-security-oauth2 ...
[INFO]                                          2.0.13.RELEASE -> 2.1.0.RELEASE
[INFO]   org.springframework.session:spring-session ...
[INFO]                                           1.3.0.RELEASE -> 1.3.1.RELEASE
[INFO]   org.springframework.session:spring-session-data-gemfire ...
[INFO]                                           1.3.0.RELEASE -> 1.3.1.RELEASE
[INFO]   org.springframework.session:spring-session-data-mongo ...
[INFO]                                           1.3.0.RELEASE -> 1.3.1.RELEASE
[INFO]   org.springframework.session:spring-session-data-redis ...
[INFO]                                           1.3.0.RELEASE -> 1.3.1.RELEASE
[INFO]   org.springframework.session:spring-session-hazelcast ...
[INFO]                                           1.3.0.RELEASE -> 1.3.1.RELEASE
[INFO]   org.springframework.session:spring-session-jdbc ...
[INFO]                                           1.3.0.RELEASE -> 1.3.1.RELEASE
[INFO]   org.springframework.social:spring-social-facebook-web ...
[INFO]                                                2.0.3.RELEASE -> 3.0.0.M1
[INFO]   org.thymeleaf:thymeleaf ............... 2.1.5.RELEASE -> 3.0.6.RELEASE
[INFO]   org.thymeleaf:thymeleaf-spring4 ....... 2.1.5.RELEASE -> 3.0.6.RELEASE
[INFO]   org.thymeleaf.extras:thymeleaf-extras-java8time ...
[INFO]                                           2.1.0.RELEASE -> 3.0.0.RELEASE
[INFO]   org.thymeleaf.extras:thymeleaf-extras-springsecurity4 ...
[INFO]                                           2.1.3.RELEASE -> 3.0.2.RELEASE
[INFO]   org.webjars:hal-browser ........................... 9f96c74 -> 3325375
[INFO]   org.webjars:webjars-locator ........................... 0.32 -> 0.32-1
[INFO]   org.xerial:sqlite-jdbc .............................. 3.15.1 -> 3.16.1
[INFO]   org.yaml:snakeyaml ...................................... 1.17 -> 1.18
[INFO]   xml-apis:xml-apis .................................... 1.4.01 -> 2.0.2
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]

versions:display-plugin-updates

和上面那个相似,不过是检测maven 插件是不是最新的

versions:display-property-updates

查看属性有无最新版本?

versions:update-properties 和versions:update-property

versions:lock-snapshots 锁定快照

searches the pom for all -SNAPSHOT versions and replaces them with the current timestamp version of that -SNAPSHOT, e.g. -20090327.172306-4

versions:unlock-snapshots 解锁快照

versions:use-releases 将快照替换为正式版本

资料来源:

  1. 官网--Updating POM Versions
  2. 官网--Versions Maven Plugin

© 著作权归作者所有

洞渊龙王

洞渊龙王

粉丝 1
博文 47
码字总数 20916
作品 0
海淀
程序员
私信 提问
使用maven在dos下构建java项目,构建java web项目

1.maven升级 大家可以看得到我的第一篇文章里面用的是maven 2.2.1,但是现在已经出了maven更高级的版本,我们升级以获得更多更酷的新特性,以及避免一些旧的bug,且maven新版本是向下兼容,所...

双月通天
2015/08/22
0
0
SpringBootSwaggerStarter 2.0.5 发布,补充 UI 文件

SpringBootSwaggerStarter,用于简化在spring boot的web项目中使用swagger展示api的操作,依据spring boot官方的命名建议,在maven中使用“swagger-spring-boot-starter”的坐标。 此次升级,...

阿信sxq
2018/09/17
1K
14
jboot 2.0.9 发布,升级分布式事务 fescar 到 seata

Jboot 是一个基于 JFinal、JFinal-Undertow、Dubbo 等开发的微服务框架,帮助开发者降低微服务开发门槛。同时完美支持在 idea、eclipse 下多 maven 模块,对java代码、html、css、js 等资源文...

理工男海哥
05/08
0
0
Gradle 4.3.1 发布,项目自动化构建工具

Gradle 4.3.1 已发布,Gradle 就是可以使用 Groovy 来书写构建脚本的构建系统,支持依赖管理和多项目,类似 Maven,但比之简单轻便。 这个 bug 修复版本解决了 Gradle 4.3 中的 3 个回归错误...

周其
2017/11/09
1K
16
maven发布项目到私服-snapshot快照库和release发布库的区别和作用及maven常用命令

在日常的工作中由于各种原因,会出现这样一种情况,某些项目并没有打包至mvnrepository。如果采用原始直接打包放到lib目录的方式进行处理,便对项目的管理带来一些不必要的麻烦。例如版本升级...

嗯哼9925
2017/11/15
0
0

没有更多内容

加载失败,请刷新页面

加载更多

docker百万连接设置相关资料

借助Docker单机秒开数十万TCP连接

youngjdong
8分钟前
0
0
这可能是史上最全 Redis 高可用解决方案总结

本文主要针对 Redis 常见的几种使用方式及其优缺点展开分析。 一、常见使用方式 Redis 的几种常见使用方式包括: 1.Redis 单副本; 2.Redis 多副本(主从); 3.Redis Sentinel(哨兵); 4....

别打我会飞
10分钟前
0
0
Qt编写数据可视化大屏界面电子看板11-自定义控件

一、前言 说到自定义控件,我是感觉特别熟悉的几个字,本人亲自原创的自定义控件超过110个,都是来自各个行业的具体应用真实需求,而不是凭空捏造的,当然有几个小控件也有点凑数的嫌疑,在编...

飞扬青云
13分钟前
0
0
第二讲:编写UDP Socket小程序

1、编写服务器端代码 文件-->新建 新建一个控制台程序: 下面用的是一张旧图,只要点确认就可以了。 切换到FileView视图 编译、链接 StdAfx.cpp( 里面的代码不用修改) 编辑UDPServer.cpp文...

一匹狼工作室
13分钟前
1
0
android ------ 实现高德定位并获取相应信息 ( 最新版高德SDK 和 Android SDK版本)

Android开发项目时常常会遇到定位这个功能, 很久以前写过一篇了,官方也更新了一些东西,我也更新下 以前使用的是jar包 导入来实现高德定位 老版本 链接:https://blog.csdn.net/DickyQie/...

切切歆语
16分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部