Maven pom版本继承



我有三个项目Parent,Child,SubChild。

项目母公司pom如下:

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
<groupId>mu.parent</groupId>
<artifactId>parent-system</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

项目子项目pom定义如下,其父项目定义如下:

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>mu.parent</groupId>
<artifactId>parent-system</artifactId>
<version>1.0</version>
</parent>

<groupId>mu.dummy.child</groupId>
<artifactId>child-backend</artifactId>
<name>child-backend</name>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>subChild-app</module>

</modules>

...

现在subChild-pom如下所示,子项被定义为subChild:的父项

<parent>
<groupId>mu.dummy.child</groupId>
<artifactId>child-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>mu.dummy.subchild</groupId>
<artifactId>subchild-backend</artifactId>
<name>subchild-backend</name>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>org.project.test</groupId>
<artifactId>project</artifactId>
<version></version> --version of parent-system???
</dependency>
</dependencies>

是否可以在不进行硬编码的情况下,在子系统后端获得父系统(1.0(的版本?

您可以使用CI友好的版本,并为这些版本编写${revision},在主pom中设置此属性(从中构建所有内容(。

不过,您需要使用flashMaven插件来在存储库中获得适当的POM。

不久前我问了一个类似的问题,并确定groovy-maven-plugin适用于此。看看这个答案。

最新更新