【发布时间】:2016-01-10 21:43:03
【问题描述】:
我的多模块项目的父 POM 中有这个 dependencyManagement:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>A</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>B</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>C</artifactId>
<version>1.1</version>
</dependency>
</dependencyManagement>
在每个子模块 POM 中:
模块 A:
<parent>
<groupId>${project.groupId}</groupId>
<artifactId>ParentId</artifactId>
<version>1.0</version>
</parent>
<artifactId>A</artifactId>
<version>3.5</version>
<packaging>nbm</packaging>
模块 B:
<parent>
<groupId>${project.groupId}</groupId>
<artifactId>ParentId</artifactId>
<version>1.0</version>
</parent>
<artifactId>B</artifactId>
<version>1.0</version>
<packaging>nbm</packaging>
模块 C:
<parent>
<groupId>${project.groupId}</groupId>
<artifactId>ParentId</artifactId>
<version>1.0</version>
</parent>
<artifactId>C</artifactId>
<version>1.1</version>
<packaging>nbm</packaging>
每次我们要发布时,我们都必须检查每个子模块中的版本是否与dependencyManagement中的版本相同(开发人员每次更改时都被要求更改两个地方的版本)。
有什么方法可以自动检查版本是否相同?如果版本不一样,如何自动更改?
【问题讨论】:
-
模块 B 和 C 的 artifactId 不应该是
B和C吗?? -
您应该考虑在父 pom 的 maven 属性中定义版本,并在子模块中引用该属性。这样他们就会同步。
-
如果你有一个多模块构建,每个模块/子模块都应该与父模块具有相同的版本,这样你就违反了多模块构建的想法,这会导致你遇到问题。
-
@vikingsteve 你是对的。我编辑了:)
-
@SanjeevGour 如果我按照你说的做,我会收到一条警告:“版本包含一个表达式,但应该是一个常量。强烈建议修复这些问题,因为它们会威胁到你的稳定性构建。因此,未来的 Maven 版本可能不再支持构建此类格式错误的项目。”
标签: maven maven-release-plugin multi-module