父 Pom 获取子版本 Pom/dependency

Parent Pom get version of Child Pom/dependency

我有一个类似下面的项目

mainProject - 多模块项目结构:

pom.xml
newfolder/pom.xml

其他项目:

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

见下文:

主项目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>   

其他项目:

<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

任何帮助都会很棒!

我能够通过将 ${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>