java - Maven 如何将传递依赖添加到类路径中?

标签 java maven classpath transitive-dependency

我对maven如何处理传递依赖以及它如何写入类路径感到非常困惑。

假设我有两条 E 路径(A、B、C、D、E 是 ejb):
1. A<---B<---E(E 依赖(comile)于 B,而 B 又依赖于 A)
2. A<---C<---D<---E(所有依赖均为编译依赖)

问题是:E 是如何构建的,以及 E 的类路径(META-INF)中有哪些 Artifact 。

非常感谢!

最佳答案

Maven 将使用“最近的定义”来确定在构建中使用哪个版本的依赖项 E。来自 official Maven documentation :

"nearest definition" means that the version used will be the closest one to your project in the tree of dependencies, eg. if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0

在您的示例中:

1. A <--- B <--- E 1.0
2. A <--- C <--- D <--- E 2.0

将使用依赖项 E1.0 版本,因为构建 A 时,该版本的路径较短。

关于java - Maven 如何将传递依赖添加到类路径中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30613713/

相关文章:

java - HADOOP - 1.2.1 稳定版的字数统计示例

Maven 嵌入式部署不适用于 org.apache.httpcomponents.httpclient 版本 4.4

java - 如何从使用在 "Classpath"中添加的 *.jar 文件的 eclipse java 项目创建 jar 文件

java - native 查询错误

java - Hibernate - 子级错误不会回滚父级插入数据库

maven - 将 Maven 的本地存储库位置指定为 CLI 参数

java - 我可以使用类路径覆盖正在运行的 jar 中的文件吗?

Eclipse "Open Type"窗口显示双

java - 命名 Ant 目标的最佳做法是什么?

java - 一维java数组的问题