Maven 父子继承依赖不起作用

问题描述 投票:0回答:1

下面是我的parent-pom.xml :-

<groupId>com.example.parent</groupId>
<artifactId>example-parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>sample-parent</name>

<dependencyManagement>
  <dependency>
        <groupId>org.testcontainers</groupId>
        <artifactId>testcontainers-bom</artifactId>
        <version>1.19.1</version>
        <type>pom</type>
  </dependency>
</dependencyManagement>

在子 pom 中,我添加了以下依赖项:- 子 pom.xml

<groupId>com.example.child</groupId>
<artifactId>example-child</artifactId>
<version>1.0.0</version>
<name>sample-child</name>
<packaging>jar</packaging>

<parent>
   <groupId>com.example.parent</groupId>
   <artifactId>example-parent</artifactId>
   <version>1.0.0</version>
</parent>

<dependencies>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>testcontainers</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>spock</artifactId>
      <scope>test</scope>
    </dependency>
</dependencies>

但是,当我构建它时,出现以下错误:-

'dependencies.dependency.version' for org.testcontainers:testcontainers:jar is missing. @ com.example.child:sample-child:${revision}, C:\...\pom.xml, line 438, column 17

查看这里的各种帖子,它应该可以工作,但不知何故它在我的情况下不起作用。不知道我错过了什么。

maven hierarchy
1个回答
0
投票

您需要将

<scope>import</scope>
添加到父 pom 中的依赖项中。请参阅如何在 Maven 中使用 BOM 文件?了解更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.