Maven父到子继承依赖不起作用

x6492ojm  于 12个月前  发布在  Maven
关注(0)|答案(1)|浏览(241)

下面是我的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中,我添加了以下依赖项:- child-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


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

tzxcd3kk

tzxcd3kk1#

您需要将<scope>import</scope>添加到父pom中的依赖项。有关详细信息,请参阅How to use BOM file with Maven?

相关问题