简体   繁体   English

如何使用模块化Maven项目管理版本号?

[英]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.

相关问题 如何在全球范围内管理不同Maven项目之间的依赖关系? - How do to manage Dependencies between different maven projects, globally? 您如何对项目进行版本控制和管理发布? - How do you version your projects and manage releases? 如何升级maven插件的版本? - How do I upgrade the version of a maven plugin? 如何在兄弟项目之间实现Maven源依赖? - How do I implement maven source dependency among sibling projects? 如何设置 VSCODE 来创建 Maven 项目? - How do I setup VSCODE to create Maven projects? 如何在Eclipse中管理不同项目的不同Maven设置? - How to manage different maven setting in eclipse for different projects? 如何在eclipse中正确管理多个独立的maven项目版本控制 - How to properly manage multiple independent maven projects versioning in eclipse 如何管理不在同一目录结构中的 maven 子项目? - How to manage maven sub projects not in the same directory structure? 如何使用 Maven Javadoc 插件正确链接到模块化依赖项? - How to properly link to a modularized dependency using the Maven Javadoc Plugin? 如何确保git存储库中的所有Java项目都具有最新或所需的maven依赖项版本? - How can i ensure all my java projects in a git repository have latest or desired version of maven dependency?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM