Master Maven Version Management with BOM: Streamline Your Java Projects
This article explains how to use Maven parent POMs, properties, and BOM (Bill of Materials) to centrally manage version numbers across multi‑module Java projects, resolve dependency conflicts, and simplify builds for backend development teams.
Managing project versions and structuring Maven modules can be challenging, but using a parent POM with shared properties and a Maven BOM simplifies the process.
Define a top‑level parent module (e.g., <groupId>com.pilot.basic</groupId>, <artifactId>basic-parent</artifactId>) and set a ${revision} property for the version. Child modules inherit this version, allowing you to omit explicit groupId and version entries.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<groupId>com.pilot.basic</groupId>
<artifactId>basic-parent</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<properties>
<revision>1.0.0-SNAPSHOT</revision>
<java_source_version>1.8</java_source_version>
<java_target_version>1.8</java_target_version>
<file_encoding>UTF-8</file_encoding>
</properties>
</project>Child modules reference the parent with <parent> and inherit ${revision}, ensuring consistent versions across the hierarchy.
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.pilot.basic</groupId>
<artifactId>basic-parent</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>basic-service</artifactId>
<packaging>pom</packaging>
</project>When releasing to a Maven repository, updating the single ${revision} property in the parent POM updates all module versions.
BOM (Bill of Materials) is a Maven feature that defines a set of compatible dependency versions. By importing a BOM, developers no longer need to specify individual versions, and the BOM maintainer ensures compatibility.
Using a BOM helps avoid version conflicts, such as when different transitive dependencies require different versions of the same library, leading to runtime errors like NoSuchMethodError or ClassNotFoundException.
To create a BOM, define a regular POM that only contains a <dependencyManagement> section with the desired dependencies and their versions.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pilot.basic</groupId>
<artifactId>basic-bom</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid_version}</version>
</dependency>
<!-- more dependencies -->
</dependencies>
</dependencyManagement>
</project>To use the BOM, import it in the parent project's <dependencyManagement> with type="pom" and scope="import", then add regular dependencies without versions in child modules.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.pilot.basic</groupId>
<artifactId>basic-bom</artifactId>
<version>${revision}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>When a specific library needs a different version, simply add a <version> element to override the BOM's version.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect's Alchemy Furnace
A comprehensive platform that combines Java development and architecture design, guaranteeing 100% original content. We explore the essence and philosophy of architecture and provide professional technical articles for aspiring architects.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
