Maven父POM与BOM依赖关系管理 [英] Maven parent POM vs BOM dependency management

查看:1166
本文介绍了Maven父POM与BOM依赖关系管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个Maven父POM root,它在依赖项管理中定义了foo:bar:1.0.0.我有另一个父POM parent,它使用root作为父(只是将另一个图层添加到示例中).最后,我有一个物料清单bom,它使用root作为其父级,但在其依赖项管理中重新定义了foo:bar:2.0.0.

Let's say I have a maven parent POM root which defines foo:bar:1.0.0 in dependency management. I have another parent POM parent which uses root as parent (just to add another layer to the example). Lastly I have a bill of materials bom which uses root as its parent but redefines foo:bar:2.0.0 in its dependency management.

在我的项目app中,我从parent继承,然后

In my project app I inherit from parent and then I import the BOM in the dependency management section of app

root (foo:bar:1.0.0) <- parent <- app+bom
 ^
 |
bom (foo:bar:2.0.0)

哪个依赖项管理部分胜出?我可以获得哪个版本的foo:bar?

Which dependency management section wins? Which version of foo:bar do I get?

我知道,如果直接将foo:bar包含在app的依赖项管理部分中,它将覆盖从父级继承的内容.但是,导入在依赖关系管理部分中的BOM是否等于直接将其包含在依赖关系管理部分中,并且足以覆盖父级的BOM?还是从父级的依赖项管理继承的foo:bar优先?

I know that if I were to directly include foo:bar in the dependency management section of app, it would override that inherited from the parent. But is importing a BOM in the dependency management section equivalent to directly including it in the dependency management section, and sufficient to override that of the parent? Or does the inherited foo:bar from the parent's dependency management take precedence?

推荐答案

根据maven优先级规则,根目录中的版本将获胜,因此您将获得foo:bar:1.0.0,您将能够看看您是否看过有效的POM.我认为这会使BOM表项目的效率降低,因为您不能使用它来覆盖父级的版本,而必须在应用程序或父级中声明版本.

According to the maven precedence rules, the version from the root will win and therefore you will get foo:bar:1.0.0, which you will be able to see if you look at the effective POM. I think that this makes a BOM project less effective since you cannot use it to override the version from the parent and have to declare the version in the app or in the parent.

优先级

因此,有多种确定版本的方法, 这意味着有一个优先顺序.

So, there are multiple ways of deciding the versions, which means there is an order of precedence.

  • POM中直接声明中提供的版本具有最高优先级.
  • 父pom中提供的版本优先.
  • 导入的pom版本排名第三
  • 最后,无论我们从依赖关系调解中得到什么
  • Versions provided in the direct declaration in POM take the highest precedence.
  • Version provided in parent pom takes second precedence.
  • Version from imported pom takes third place
  • Lastly, whatever we get from dependency mediation

这篇关于Maven父POM与BOM依赖关系管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆