Maven’s Bill of Materials (BOM)
If you are a regular user of Maven you might have come across a very common issue — version control.
Let me set some example which would probably hits closer to home (or work ☺):
I’m using Spring as my app core framework — how can I keep every module in check as to which version of Spring should it use?
or perhaps …
We’re using JBoss 6.x as our app server — how would I know which version of hibernate is this container bundled with? Am I expected to sift through the guts of the server to find the version?
Of course not. Serious tech and libraries provide you with something better: Jersey, RESTeasy, JBoss, Spring — they all provide their own BOM you could use.
Maven is the BOMb
That’s where Maven’s BOM (or Bill of Materials) come in. BOMs’ provides you the flexibility to add dependencies to your module without worrying on which version should you depend on.
Then how does it work?
A bill of materials (BoM) is a list of the parts or components that are required to build a product.†
First of all, BOMs are ordinary pom.xml files — they contain no source code and their only purpose is to declare their bundled modules. Think of it as a list of ingredients one would need to use in order to use that tech. Red Hat RnD would have probably said something along the lines of:
We have just released JBoss EAP 6.4 for public use. These are the tech that we have provided with the app container — add the BOM to your app and you’re good to go.
And indeed they did in their JBoss development guide (specifically in the JBoss EAP BOMs and Quickstarts section):
There are two approaches to direct Maven to use the JBoss EAP 6 Maven Repository in your project: You can configure the…access.redhat.com
What do you need to do? Declare the BOM in your pom.xml file (typically in your parent POM) …
… and you will have all the tech within your reach.
Would you need hibernate in one of your app modules? Simples — add the following as a dependency:
Tah dah! You will never have to worry about another version ever again. Isn’t it a little piece of heaven?
Taking it a step further: creating your own BOM!
Perhaps it doesn’t make much sense for small web applications, but for enterprise applications which span over hundreds of modules — you could imagine the version chaos that would ensue.
You could easily create your own BOM flavour by creating a fresh pom.xml
<!-- add your module declarations here! -->
and declare the BOM in your app.