【问题标题】:Parent Pom get version of Child Pom/dependency父 Pom 获取子 Pom/依赖的版本
【发布时间】:2020-07-12 09:01:00
【问题描述】:

我有一个类似下面的项目

mainProject - 多模块项目结构:

pom.xml
newfolder/pom.xml

其他项目:

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>

新文件夹/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

任何帮助都会很棒!

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      • 2017-02-22
      • 2018-03-05
      • 2016-12-17
      • 2018-04-12
      • 1970-01-01
      • 2023-03-10
      相关资源
      最近更新 更多