Bill of Materials (BOM)
About
A Bill of Materials (BOM) is a special type of Maven POM (Project Object Model) file that manages dependency versions centrally. Instead of specifying versions for each dependency separately, a BOM allows defining them once in a single place, ensuring consistency across multiple modules or projects.
BOM helps prevent version mismatches, reduces dependency conflicts, and simplifies project maintenance.
Why Use a BOM?
Problem Without BOM (Version Inconsistency & Repetition)
Without a BOM, we must explicitly declare versions for each dependency:
This duplicates version numbers across dependencies, making version upgrades error-prone.
Solution With BOM (Centralized Versioning)
With a BOM, versions are managed once at a central location:
Now, we can add dependencies without specifying versions:
Maven automatically picks up versions from the BOM.
How to Create a BOM ?
A BOM is just a POM file with -
Packaging type set to pom
Dependencies listed without scope
Version numbers specified centrally
Example BOM POM (my-bom/pom.xml
)
my-bom/pom.xml
)Any project that imports this BOM inherits the defined versions without needing to specify them.
Using a Custom BOM in a Project
Once a BOM is created, import it in a project’s pom.xml
:
Now, dependencies can be added without version numbers:
Maven will use the versions from the imported BOM.
Maven's Built-in BOMs
Maven provides several official BOMs that help with version consistency:
Spring Boot BOM (Recommended for Spring Projects)
This ensures all Spring Boot starters use compatible versions.
Jakarta EE BOM (For Enterprise Java Applications)
Ensures all Jakarta EE dependencies are consistent.
Benefits of Using BOM
Version Consistency
Hard to maintain
Ensured centrally
Conflict Prevention
Manual resolution
Automatic handling
Code Maintenance
Redundant versioning
Cleaner pom.xml
Scalability
Difficult for large projects
Best suited for enterprise applications
Last updated
Was this helpful?