父Pom获取子Pom /依赖性的版本

时间:2020-03-31 17:52:55

标签: maven-2 pom.xml multi-module parent-pom

我有一个类似以下的项目

mainProject-多模块项目结构:

pom.xml
newfolder/pom.xml

otherProject:

otherProject.pom.xml with mainProject.pom.xml as its parent pom and newFolder/pom.xml as a dependency.

见下文:

mainProject pom.xml:

<groupId>test.test</groupId>
<artifactId>mainProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
    <module>newFolder</module>
</modules>
<dependency>
    <groupId>test.test</groupId>
    <artifactId>newFolder</artifactId>
    <version>${project.version}</version>
</dependency>

newfolder / pom.xml:

<groupId>test.test</groupId>
<artifactId>newFolder</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
    <groupId>test.test</groupId>
    <artifactId>mainProject/artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>   

otherProject:

<parent>
    <groupId>test.test</groupId>
    <artifactId>mainProject</artifactId>
    <version>1.0-SNAPSHOT/version>
</parent>
<dependency>
    <groupId>test.test</groupId>
    <artifactId>newFolder</artifactId>
</dependency>

问题是当我尝试构建otherProject时,它找不到newfolder的版本,因为它没有拉入我构建的项目的版本中,而仍在寻找newfolder 1.0-SNAPSHOT

任何帮助都会很棒!

1 个答案:

答案 0 :(得分:0)

通过将$ {project.parent.version}添加到父pom依赖项中,可以实现我希望的行为。例如:

<groupId>test.test</groupId>
<artifactId>mainProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
    <module>newFolder</module>
</modules>
<dependency>
    <groupId>test.test</groupId>
    <artifactId>newFolder</artifactId>
    <version>${project.parent.version}</version>
</dependency>