我有两个项目:父项目:A,子项目:B
一个/ pom.xml:
<groupId>com.dummy.bla</groupId>
<artifactId>parent</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>
在B/pom.xml中,我有:
<parent>
<groupId>com.dummy.bla</groupId>
<artifactId>parent</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<groupId>com.dummy.bla.sub</groupId>
<artifactId>kid</artifactId>
我想要B继承父版本,所以在我的情况下,我需要把0.1-SNAPSHOT的唯一地方是A/pom.xml。但是如果我从父部分的B/pom.xml中删除<version>0.1-SNAPSHOT</version>, maven会抱怨父部分缺少版本。
是否有一种方法可以使用${project。Version}或类似的东西,以避免出现01。-快照在两个poms?
It worked for me using BOM approach on parent pom.xml:
My scenario:
- parent pom.xml 0.0.0.1-SNAPSHOT
- sub-project1
- sub-project2 (sub-project1 is a dependency)
<properties>
<revision>0.0.0.1-SNAPSHOT</revision>
</properties>
<groupId>com.example</groupId>
<artifactId>commons</artifactId>
<packaging>pom</packaging>
<version>${revision}</version>
<name>commons</name>
<description>parent module of commons project</description>
<modules>
<module>sub-project1</module>
<module>sub-project2</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<type>pom</type>
<version>2.6.4</version>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.example.commons</groupId>
<artifactId>sub-project1</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</dependencyManagement>
子项目pom.xml可以从父项目继承${revision}编号,而且实际列出的依赖项不需要显式地提到标记
<parent>
<groupId>com.example</groupId>
<artifactId>commons</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.example.commons</groupId>
<artifactId>sub-project2</artifactId>
<version>${revision}</version>
<name>sub-project2</name>
<description>implement sub-project2 </description>
<dependencies>
<dependency>
<groupId>com.example.commons</groupId>
<artifactId>sub-project1</artifactId>
</dependency>
</dependencies>