简体   繁体   English

maven 依赖树在哪一层是来自父项目的依赖

[英]On which level of the maven dependency tree are dependencies from the parent project

I have a parent pom which has a dependency to third party jar A with version 1.0.我有一个父 pom,它依赖于版本 1.0 的第三方 jar A。 Then I have a child project which inherits from the parent pom.然后我有一个从父 pom 继承的子项目。 This child project defines a dependency to library B which itself has the dependency to the third party jar A with version 1.1.这个子项目定义了对库 B 的依赖,它本身依赖于版本 1.1 的第三方 jar A。

Does the dependency tree look like this(and therefore version 1.0 is pulled in):依赖树看起来像这样吗(因此引入了 1.0 版):

Child->A(version 1.0) Child->B->A(version 1.1) Child->A(version 1.0) Child->B->A(version 1.1)

On which level of the dependency tree are the dependencies of the parent POM?父 POM 的依赖关系在依赖树的哪一层?

Before dependencies are resolved, the parent and child POM are first combined into an "effective POM".在解决依赖关系之前,首先将父子 POM 组合成一个“有效的 POM”。 You can display the effective POM using mvn help:effective-pom .您可以使用mvn help:effective-pom显示有效的 POM。 Hence your dependency tree becomes:因此你的依赖树变成:

  (Effective POM) -> A:1.0
  (Effective POM) -> B     -> A:1.1

The effect is the same as if you had declared the A:1.0 dependency in the child POM.效果与您在子 POM 中声明 A:1.0 依赖项相同。 Since dependencies closer to the root "win" in Maven, A:1.0 is used.由于依赖关系更接近 Maven 中的根“win”,因此使用 A:1.0。

Also, if both the parent and child POM declare a dependency to the same module, the version specified by the child overrides the one specified by the parent (= becomes the version in the effective POM).此外,如果父 POM 和子 POM 都声明了对同一模块的依赖,则子指定的版本会覆盖父指定的版本(= 成为有效 POM 中的版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM