java Maven BOM [物料清单] 依赖性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38496022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:27:19  来源:igfitidea点击:

Maven BOM [Bill Of Materials] Dependency

javaspringmavendependenciespom.xml

提问by Ajeet Deginal

I am not understanding what is the purpose of bom object? and I am working on Spring 3.2.8 version and with JBoss server, so which bom dependency I need to use? When I mention the following dependency in pom.xml:

我不明白 bom 对象的目的是什么?我正在使用 Spring 3.2.8 版本和 JBoss 服务器,那么我需要使用哪个 bom 依赖项?当我在 pom.xml 中提到以下依赖项时:

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>4.0.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
</dependency>

Does the jar file gets downloaded into my Maven Dependencies?

jar 文件是否下载到我的 Maven 依赖项中?

回答by Anton Koscejev

What is the purpose of bom object?

bom对象的目的是什么?

Maven parent-child relationship is very handy for managing dependencies of multiple projects in a single place. However, Maven projects can have only one (direct) parent. So imports were introduced for dependency management to allow using several projects for managing your dependencies. With an import you can define a single dependency like this and get multiple dependencies managed - handy! Although you could import any project, BOM is a special project designed to be used for imports like this. Usually a BOM project will have very little defined besides dependencyManagementsection, and will not have any unrelated dependencies, to avoid affecting your main project too much.

Maven 父子关系对于在一个地方管理多个项目的依赖关系非常方便。但是,Maven 项目只能有一个(直接)父项。因此引入了依赖项管理的导入,以允许使用多个项目来管理您的依赖项。通过导入,您可以像这样定义单个依赖项并管理多个依赖项 - 方便!尽管您可以导入任何项目,但 BOM 是一个特殊的项目,旨在用于此类导入。通常一个BOM项目除了dependencyManagementsection之外几乎没有定义,不会有任何不相关的依赖,以免对你的主项目造成太大影响。

Which bom dependency I need to use?

我需要使用哪个 bom 依赖项?

BOM is not a requirement, you don't need to use either. Instead, you could define all managed dependencies in dependencyManagement section yourself. These can include Spring, JBoss and any other dependencies. BOM, however, simplifies this for you significantly. You can add as many BOMs as you want, so add both! But as @Jesper mentions, don't forget to use correct versions. When using multiple BOMs their order will matter if they both reference a common dependency.

BOM 不是必需的,您也不需要使用。相反,您可以自己在 dependencyManagement 部分中定义所有托管依赖项。这些可以包括 Spring、JBoss 和任何其他依赖项。但是,BOM 为您显着简化了这一过程。您可以根据需要添加任意数量的 BOM,因此请同时添加!但正如@Jesper 提到的,不要忘记使用正确的版本。当使用多个 BOM 时,如果它们都引用了一个共同的依赖项,它们的顺序就会很重要。

Does the jar file gets downloaded into my Maven Dependencies?

jar 文件是否下载到我的 Maven 依赖项中?

Notice BOM is <type>pom</type>, not the default jar. So there's no jar to be downloaded. A single pom.xml file will be downloaded and read by Maven.

注意 BOM 是<type>pom</type>,而不是默认值jar。所以没有要下载的jar。Maven 将下载并读取单个 pom.xml 文件。