What’s New in Maven 4? Exploring POM Model Upgrade, Flattening, and Parallel Builds
Maven 4, now in its fifth release candidate, introduces a new POM model version 4.1.0 with backward compatibility, separates build and consumer POMs to eliminate POM pollution, adds explicit artifact types for classpath and module jars, renames modules to subprojects, and brings a tree‑based lifecycle for true parallel builds, all supported by an official upgrade tool.
POM Model Upgrade: From 4.0.0 to 4.1.0
Maven 4 upgrades the POM model version to 4.1.0. The new model remains backward compatible, allowing Maven 4 to build projects that still use the old 4.0.0 POM, while new capabilities only apply when the model version is set to 4.1.0. The modelVersion element can even be omitted, as Maven can infer it from the schema.
Build POM vs. Consumer POM: Solving POM Pollution
Maven 4 distinguishes two POM types:
Build POM – used for the project's own build, containing plugin configuration, build details, parent references, and various properties.
Consumer POM – published to repositories for downstream consumers, containing only the real transitive dependencies, resolved property values, and no plugin or parent information.
Enable consumer POM flattening with the command:
mvn clean install -Dmaven.consumer.pom.flatten=trueIn Maven 3 this required the external Flatten Maven Plugin; Maven 4 provides it natively.
New Artifact Types: Explicit Classpath / Module Path Control
Previously, Maven inferred the classpath or module path based on the presence of module-info.class. Maven 4 introduces explicit types: classpath-jar – always placed on the classpath. module-jar – placed on the module path.
Example for a Lombok processor dependency:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<type>classpath-processor</type>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>Maven 4 now clearly separates the API classpath from the processor classpath, improving build semantics.
Modules Renamed to Subprojects: Preparing for Java 9
The traditional <modules> element is deprecated and replaced by <subprojects>, making multi‑module projects more intuitive for the Java module system.
<subprojects>
<subproject>project-a</subproject>
<subproject>project-b</subproject>
</subprojects>Additional improvements include automatic parent inference, automatic discovery of subprojects, unified build timestamps, and safe release semantics (any subproject failure aborts the whole release).
Tree‑Based Lifecycle: True Parallel Builds
Maven 3’s lifecycle is linear, limiting parallelism. Maven 4 introduces a tree‑based lifecycle where each subproject progresses independently once its dependencies are ready, dramatically speeding up large multi‑module builds.
mvn -b concurrent verifyConfiguration Enhancements
1. Conditional Profile Expressions
Profiles can now use full expressions instead of simple OS or JDK checks.
<condition>
exists('${project.basedir}/src/**/*.xsd') &&
length(${user.name}) > 5
</condition>2. Unified sources Model
Instead of separate sourceDirectory and testSourceDirectory elements, Maven 4 uses a unified sources block with scoped entries.
<sources>
<source>
<scope>main</scope>
<directory>my-custom-dir/foo</directory>
</source>
<source>
<scope>test</scope>
<directory>my-custom-dir/bar</directory>
</source>
</sources>Official Upgrade Tool
The new mvnup utility analyses POMs, plugins, and project structure, then generates executable upgrade suggestions.
mvnup check # generate a report only
mvnup apply # automatically apply changesThese changes together represent a semantic and practical upgrade to Maven, aligning it with modern Java modularity, cloud‑native workflows, and high‑performance CI pipelines.
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.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
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.
