Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven BOM [Bill Of Materials] Dependency

Tags:

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:

<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?

like image 802
Ajeet Deginal Avatar asked Jul 21 '16 06:07

Ajeet Deginal


People also ask

What is a BOM dependency in Maven?

BOM stands for Bill Of Materials. Maven lets us define the versions of the dependencies or transitive dependencies in a separate POM. A BOM package is a POM only jar file that is used to control the versions of a project's dependencies and provide a central place to define and update those versions.

What is BOM dependency?

Maven's dependency management includes the concept of a bill-of-materials (bom). A bom is a special kind of pom that is used to control the versions of a project's dependencies and provides a central place to define and update those versions.

How do you add a BOM to a POM?

Adding a BOM as a DependencyThe import scope set in the dependency section indicates that this dependency should be replaced with all effective dependencies declared in its POM. In other words, the list of dependencies of our BOM file will take the place of the BOM import in the POM file.

Can a BOM have a parent?

You can only have one parent, but you can import multiple BOMs into your Maven project. Also, importing a BOM will only import the dependencyManagement, while having a parent will import everything you have in that pom.


1 Answers

What is the purpose of bom object?

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 dependencyManagement section, and will not have any unrelated dependencies, to avoid affecting your main project too much.

Which bom dependency I need to use?

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.

Does the jar file gets downloaded into my Maven Dependencies?

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.

like image 95
Anton Koscejev Avatar answered Oct 20 '22 23:10

Anton Koscejev