简体   繁体   English

在子 pom 中使用依赖管理

[英]Using dependency management in a child pom

Is there any reason to use the dependency management section in a child pom?有没有理由在子 pom 中使用依赖管理部分? I'm looking at a maven project in my organization that uses inheritance and aggregation, where the parent and child poms both have a dependency management section.我正在我的组织中查看 maven 项目,该项目使用 inheritance 和聚合,其中父和子 pom 都有一个依赖管理部分。 Is the child one doing anything?孩子有事吗?

I found this question really helpful but didn't find the answer to my specific question - Differences between dependencyManagement and dependencies in Maven我发现这个问题真的很有帮助,但没有找到我的具体问题的答案-Maven 中的dependencyManagement 和dependencies 之间的区别

It can be used to control the version of transitive dependencies (libraries that your direct dependencies depend on) without adding a direct dependency.它可用于控制传递依赖项(您的直接依赖项所依赖的库)的版本,而无需添加直接依赖项。

Child POM will add or override dependency management entries of the parent POM.子 POM 将添加或覆盖父 POM 的依赖管理条目。

Keep in mind that you really, really don't want to have different versions of the same dependency in your codebase.请记住,您真的非常不想在代码库中拥有相同依赖项的不同版本。 So use this feature judiciously.因此,请明智地使用此功能。 Preferably you should have organization-wide parent POM file with all dependency versions defined and child POMs don't change them.最好你应该拥有定义了所有依赖版本的组织范围的父 POM 文件,并且子 POM 不会更改它们。

In a child pom it does not make sense.在儿童 pom 中,这是没有意义的。

In a multi module setup you should control everything for all children in the parent.在多模块设置中,您应该控制父级中所有子级的所有内容。 For example solve version conflicts / excluding transitive dependencies or import BOM files from other frameworks/libraries (for example spring boot/junit 5/etc.) makes handling of those libs including the centralised maintenance location...例如解决版本冲突/排除传递依赖或从其他框架/库(例如 spring boot/junit 5/等)导入 BOM 文件,从而处理包括集中维护位置在内的这些库......

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

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