[英]How do I manage version numbers with modularized Maven projects?
I have a fairly typical plugin architecture that looks something like this (just larger): 我有一个相当典型的插件架构,看起来像这样(略大):
project
core
data
main
ui
The parent project has a version number defined, is packaged as a pom
and defines modules in it's pom.xml
: 父项目的版本号已定义,打包为
pom
并在其pom.xml
定义模块:
<groupId>group</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
...
<modules>
<module>core</module>
<module>data</module>
<module>main</module>
<module>ui</module>
</modules>
All of the sub-modules have many references to the parent's version number everywhere . 所有子模块到处都有很多对父代版本号的引用。 Here is the an example of what the main module looks like to give you an idea:
这是一个主模块看起来可以给您一个想法的示例:
<parent>
<groupId>group</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>group</groupId>
<artifactId>project.main</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>group</groupId>
<artifactId>group.core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>group</groupId>
<artifactId>group.data</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>group</groupId>
<artifactId>group.ui</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
We're getting tired of having to change the version number over, and over, and over with each release in every parent block, in every artifact block, and in every dependency block for each and every module. 我们已经厌倦了必须在每个父模块,每个工件模块以及每个模块的每个依赖模块中的每个发行版中不断更改版本号。 On a few occasions, someone used search/replace which hit other files and messed up the build.
在某些情况下,有人使用搜索/替换命中其他文件并弄乱了构建。 We tried using properties, but that doesn't work inside the parent definitions for some nonsensical reason.
我们尝试使用属性,但是由于某些荒谬的原因,它在父级定义中不起作用。
The version number defined in the parent is the only place we care to manage. 父级中定义的版本号是我们唯一要管理的地方。 We don't even need the sub-modules to even HAVE versions (or artifacts, for that matter).
我们甚至不需要子模块来拥有HAVE版本(或工件)。 We can do this in our other Ant projects.
我们可以在其他Ant项目中做到这一点。 We can do this in our other Gradle projects.
我们可以在其他Gradle项目中做到这一点。 I can't imagine this being impossible in Maven, so I am guessing we are missing something.
我无法想象这在Maven中是不可能的,所以我想我们缺少了一些东西。
How can we define the project's version number in one place, and have that used in all of the parent, artifact, and dependency sections in our modules? 我们如何才能在一个地方定义项目的版本号,并在我们模块的所有父项,构件和依赖项部分中使用该版本号?
Version maven plugin offers the possibility of changing the subprojects version in one shot. 版本maven插件提供了一次更改子项目版本的可能性。 After including the plugin:
包含插件后:
mvn versions:set -DnewVersion=<your version>
And if everything is correct: 如果一切正确:
mvn versions:commit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.