What Maven 4 Brings: New POM Model, Flattened Consumer POMs, and Parallel Builds
Maven 4 upgrades the POM model to version 4.1.0, introduces native flattening of consumer POMs, adds explicit artifact types for classpath control, renames modules to subprojects, and implements a tree‑based lifecycle for true parallel builds, dramatically improving build speed and clarity for modern Java projects.
Since Maven 3 was released in 2010, the Java build ecosystem has evolved dramatically—modularization, parallel builds, and cloud‑native containerization have become standard, leaving Maven feeling outdated.
Maven 4 addresses these accumulated pain points. Although a final GA release date is still pending, Maven 4 has already reached its fifth release candidate (RC5), indicating near‑final stability.
POM Model Upgrade: From 4.0.0 to 4.1.0
The POM model version is now 4.1.0 :
<project xmlns="http://maven.apache.org/POM/4.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 http://maven.apache.org/xsd/maven-4.1.0.xsd">
<modelVersion>4.1.0</modelVersion>
</project>Backward compatible : Maven 4 can still build POMs that declare version 4.0.0.
New capabilities only apply when the modelVersion is 4.1.0.
The modelVersion element can be omitted; Maven will infer it from the schema.
Now is the right time to explore and prepare for upgrading.
Build POM / Consumer POM Separation: Solving "POM Pollution"
In Maven 3, a published POM contains plugin configuration, build details, parent references, and all properties, forcing downstream consumers to parse a lot of irrelevant information.
Maven 4 introduces flattening of the consumer POM:
No plugin configuration.
No parent POM reference.
No unused dependencies.
Only real transitive dependencies remain.
All properties are resolved to concrete values.
Enable it with:
mvn clean install -Dmaven.consumer.pom.flatten=trueMaven 3 required the external flatten-maven-plugin ; Maven 4 provides this as a native capability.
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 adds explicit types:
<type>classpath-jar</type>
<type>module-jar</type>Developers can now declare exactly where a dependency belongs, improving clarity for Java 9+ module systems.
Annotation Processor Types
Maven 4 adds dedicated processor types:
processor classpath-processor modular-processorExample with Lombok:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<type>classpath-processor</type>
<scope>provided</scope>
</dependency>This cleanly separates API classpath from processor classpath.
Modules Renamed to Subprojects: Aligning with Java 9
Java 9 introduced a module system that conflicted with Maven’s <modules>. Maven 4 deprecates modules and replaces it with subprojects:
<subprojects>
<subproject>project-a</subproject>
<subproject>project-b</subproject>
</subprojects>Additional improvements:
Parent inference when <parent/> is empty.
Automatic discovery of subprojects without explicit listing.
Unified build timestamps.
Secure publishing: if any subproject fails, the whole release is aborted.
Tree‑Based Lifecycle: True Parallel Builds
Maven 3’s lifecycle is linear, making parallel builds inefficient for large multi‑module projects. Maven 4 introduces a Tree‑based Lifecycle where each subproject advances independently, starting as soon as its dependencies are ready. This yields significant speed gains for big builds.
Enable it with:
mvn -b concurrent verifySmall Configuration 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
Maven 3 required separate sourceDirectory and testSourceDirectory. Maven 4 consolidates them:
<sources>
<source>
<scope>main</scope>
<directory>my-custom-dir/foo</directory>
</source>
<source>
<scope>test</scope>
<directory>my-custom-dir/bar</directory>
</source>
</sources>This model better supports multiple source directories, multiple Java versions, and projects without plugin configuration.
Official Upgrade Tool
Maven 4 provides mvnup to analyze existing projects and suggest executable migration steps:
mvnup check # generate a report
mvnup apply # apply automatic fixesThe tool inspects POM files, plugins, and project structure, then outputs concrete upgrade actions.
The migration assistance, combined with the new native features, makes moving from Maven 3 to Maven 4 a semantic and practical upgrade.
Source: xxy Open‑Source Community
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.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
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.
