【发布时间】:2009-09-08 23:36:56
【问题描述】:
假设我在如下项目中定义了两个 Maven 依赖项。
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mycompany.library</groupId>
<artifactId>mylibrary</artifactId>
<version>1.0.1</version>
<scope>compile</scope>
</dependency>
然后,在 mylibrary 中,我还定义了一个依赖项,如下所示。
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.3.1</version>
<scope>compile</scope>
</dependency>
当我打包我的项目时,我没有看到其中打包了 xstream。我认为项目的 xstream 依赖范围“test”覆盖了 mylibrary 的 xstream 依赖范围“compile”。
在这种情况下,为整个项目包含 xstream 以便子模块在项目中打包时可以访问它的最佳方式是什么?
我已经阅读了 Apache Maven 网站关于传递依赖的解释,但我很难理解它的含义,也很难找到在这种情况下的最佳实践。
【问题讨论】: