微服务聚合项目版本管理
文章目录
- 描述
- 方法一、在父项目中定义一个共同的版本号
- 方法二、maven 自带的指令
- 父模块更新到指定版本号
- 更新子模块
- 提交更新
描述
当使用微服务构建聚合项目的时候, 一个父级项目下, 会存在多个子模块. 每个模块都有自己的pom文件, 如果一个个手动去改子模块的版本的话, 一个是麻烦,并且还容易漏改或者改错. 一种方法是使用 maven 提供了相应的指令, 方便、快捷的统一修改整体项目的版本号. 第二种方法是, 在父项目根目录下的 pom.xml 文件里, 定义一个变量, 然后在这个子项目里引用这个变量. 如果想做升级的话, 只需要更改父项目里的版本号就可以了.
方法一、在父项目中定义一个共同的版本号
项目架构:
代码语言:javascript复制parentproject
|_ child1project
|_ pom.xml
|_ child2project
|_ pom.xml
...
|_ pom.xml
在父项目的 pom 文件里添加以下代码:
代码语言:javascript复制<groupId>com.parent.version</groupId>
<artifactId>controller</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<properties>
<parent.version>2.0.0-SNAPSHOT</parent.version>
</properties>
然后在子项目里引用这个变量:
代码语言:javascript复制<parent>
<groupId>com.parent.version</groupId>
<artifactId>controller</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!-- 继承父项目的版本号 -->
<version>${parent.version}</version>
方法二、maven 自带的指令
父模块更新到指定版本号
指令: mvn versions:set -DnewVersion=1.0.1-SNAPSHOT
这条指令会把父级项目的版本号改为指令的版本号.
更新子模块
指令: mvn -N versions:update-child-modules
这条指令会更新所有的子模块里的版本号, 及依赖的别的子模块的版本号, 并且会生成一个备份文件.
( 前两步如果想要还原的话, 可以执行这条zhiling: mvn versions:revert )
提交更新
指令: mvn versions:commit
这条指令会提交前两步的改动, 使之生效.
若果想查看更多maven指令的话, 可以执行这条指令查看: mvn versions:help
代码语言:javascript复制versions:commit
Removes the initial backup of the pom, thereby accepting the changes.
versions:compare-dependencies
Compare dependency versions of the current project to dependencies or
dependency management of a remote repository project. Can optionally update
locally the project instead of reporting the comparison
versions:dependency-updates-report
Generates a report of available updates for the dependencies of a project.
versions:display-dependency-updates
Displays all dependencies that have newer versions available.
versions:display-parent-updates
Displays any updates of the project's parent project
versions:display-plugin-updates
Displays all plugins that have newer versions available.
versions:display-property-updates
Displays properties that are linked to artifact versions and have updates
available.
versions:force-releases
Replaces any -SNAPSHOT versions with a release version, older if necessary (if
there has been a release).
versions:help
Display help information on versions-maven-plugin.
Call mvn versions:help -Ddetail=true -Dgoal=<goal-name> to display parameter
details.
versions:lock-snapshots
Attempts to resolve unlocked snapshot dependency versions to the locked
timestamp versions used in the build. For example, an unlocked snapshot
version like '1.0-SNAPSHOT' could be resolved to '1.0-20090128.202731-1'. If a
timestamped snapshot is not available, then the version will remained
unchanged. This would be the case if the dependency is only available in the
local repository and not in a remote snapshot repository.
versions:plugin-updates-report
Generates a report of available updates for the plugins of a project.
versions:property-updates-report
Generates a report of available updates for properties of a project which are
linked to the dependencies and/or plugins of a project.
versions:resolve-ranges
Attempts to resolve dependency version ranges to the specific version being
used in the build. For example a version range of '[1.0, 1.2)' would be
resolved to the specific version currently in use '1.1'.
versions:revert
Restores the pom from the initial backup.
versions:set
Sets the current project's version and based on that change propagates that
change onto any child modules as necessary.
versions:unlock-snapshots
Attempts to resolve unlocked snapshot dependency versions to the locked
timestamp versions used in the build. For example, an unlocked snapshot
version like '1.0-SNAPSHOT' could be resolved to '1.0-20090128.202731-1'. If a
timestamped snapshot is not available, then the version will remained
unchanged. This would be the case if the dependency is only available in the
local repository and not in a remote snapshot repository.
versions:update-child-modules
Scans the current projects child modules, updating the versions of any which
use the current project to the version of the current project.
versions:update-parent
Sets the parent version to the latest parent version.
versions:update-properties
Sets properties to the latest versions of specific artifacts.
versions:update-property
Sets a property to the latest version in a given range of associated
artifacts.
versions:use-dep-version
versions:use-latest-releases
Replaces any release versions with the latest release version.
versions:use-latest-snapshots
Replaces any release versions with the latest snapshot version (if it has been
deployed).
versions:use-latest-versions
Replaces any version with the latest version.
versions:use-next-releases
Replaces any release versions with the next release version (if it has been
released).
versions:use-next-snapshots
Replaces any release versions with the next snapshot version (if it has been
deployed).
versions:use-next-versions
Replaces any version with the latest version.
versions:use-reactor
Replaces any versions with the corresponding version from the reactor.
versions:use-releases
Replaces any -SNAPSHOT versions with the corresponding release version (if it
has been released).