java - 使用 Maven 管理多重依赖

标签 java maven pom.xml

我是 Java 和 Maven 新手。 我有 2 个项目代码(A 和 B),这样。 A依赖于B,B依赖于C(第三方) 但项目 A 也依赖于 C。

我可以在 A 的 pom.xml 中指定从 B 获取 C 的依赖吗?

我只想在 A 的 pom.xml 中提及对 B 及其 Jars 的依赖。

这样,如果 B 的 pom.xml 中的 C 发生任何版本更改,我就不必在 A 的 pom.xml 中进行相同的更改

最佳答案

Can I specify in pom.xml of A to take the dependency of C from B?

如果 A 依赖于 B,而 B 又依赖于 C,则 A 会传递性地拉取 C 的依赖。因此,您无需在 A 中声明 C,甚至不应避免使用不同的版本。

<强> Transitive Dependencies

Transitive dependencies are a new feature in Maven 2.0. This allows you to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically.

关于java - 使用 Maven 管理多重依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45387705/

相关文章:

java - Wro4j - 犀牛实现

java - Maven:在属性中设置代码变量

maven - maven dependentecyManagement 是否影响pluginManagement 传递依赖?

java - 使用 Maven 从 pom.xml 构建项目后,我如何使用它的资源

java - 使用 mvnDebug 崩溃,错误代码为 'Cannot load this JVM TI agent twice error'

java - 如何在 Google-App 上允许快速发布请求?

java - 我的项目将部署在没有中间件的服务器上。这是什么意思?

java - 如何计算二进制数字中1的数量?

java - Java中的音频指纹识别系统

java - checkstyle 配置期间失败 : unable to parse configuration stream