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

x6492ojm  于 2024-01-06  发布在  Maven
关注(0)|答案(1)|浏览(326)

下面是我的parent-pom.xml:

  1. <groupId>com.example.parent</groupId>
  2. <artifactId>example-parent</artifactId>
  3. <version>1.0.0</version>
  4. <packaging>pom</packaging>
  5. <name>sample-parent</name>
  6. <dependencyManagement>
  7. <dependency>
  8. <groupId>org.testcontainers</groupId>
  9. <artifactId>testcontainers-bom</artifactId>
  10. <version>1.19.1</version>
  11. <type>pom</type>
  12. </dependency>
  13. </dependencyManagement>

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

  1. <groupId>com.example.child</groupId>
  2. <artifactId>example-child</artifactId>
  3. <version>1.0.0</version>
  4. <name>sample-child</name>
  5. <packaging>jar</packaging>
  6. <parent>
  7. <groupId>com.example.parent</groupId>
  8. <artifactId>example-parent</artifactId>
  9. <version>1.0.0</version>
  10. </parent>
  11. <dependencies>
  12. <dependency>
  13. <groupId>org.testcontainers</groupId>
  14. <artifactId>testcontainers</artifactId>
  15. <scope>test</scope>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.testcontainers</groupId>
  19. <artifactId>junit-jupiter</artifactId>
  20. <scope>test</scope>
  21. </dependency>
  22. <dependency>
  23. <groupId>org.testcontainers</groupId>
  24. <artifactId>spock</artifactId>
  25. <scope>test</scope>
  26. </dependency>
  27. </dependencies>


但是,当我构建它时,低于错误:

  1. '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?

相关问题