What Maven 4 Brings: New POM Model, Flattened Consumer POMs, and Parallel Build Power
Maven 4 introduces a revamped POM model (4.1.0), separates build and consumer POMs to eliminate unnecessary metadata, adds explicit artifact types for classpath and module jars, renames modules to subprojects, adopts a tree‑based lifecycle for true parallel builds, and provides powerful configuration and upgrade tools, all aimed at modern Java projects.
POM Model Upgrade: 4.0.0 → 4.1.0
Maven 4 moves the POM model version from 4.0.0 to 4.1.0, enabling backward compatibility while allowing new features that are only effective for the 4.1.0 model. The modelVersion element can be omitted because Maven can infer it from the schema.
<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>Build POM / Consumer POM Separation
This is Maven 4’s most disruptive change: the POM that is published to repositories (Build POM) no longer contains plugin configuration, build details, parent references, or unused dependencies, while the Consumer POM contains only the real transitive dependencies and resolved properties. This flattening eliminates “POM pollution” for downstream users.
Backward compatible – Maven 4 can still build projects using a 4.0.0 POM.
New capabilities apply only to the 4.1.0 model.
Enable flattening with:
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
Maven 3 inferred the classpath or module path based on the presence of module-info.class. Maven 4 introduces explicit types so developers can declare where a dependency belongs.
<type>classpath-jar</type>
<type>module-jar</type>Example with Lombok:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<type>classpath-processor</type>
</dependency>Modules Renamed to Subprojects
To ease the transition to Java 9 modules, Maven 4 deprecates the modules element and replaces it with subprojects, which are automatically discovered.
<subprojects>
<subproject>project-a</subproject>
<subproject>project-b</subproject>
</subprojects>Tree‑Based Lifecycle for Parallel Builds
Maven 3’s lifecycle is linear, making parallel builds inefficient. 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 verifyEnhanced Configuration: Conditional Profiles
Profiles can now use full expression language instead of simple OS or JDK checks.
<condition>
exists('${project.basedir}/src/**/*.xsd') && length(${user.name}) > 5
</condition>Unified sources Model
Maven 4 replaces the separate sourceDirectory and testSourceDirectory tags with a unified sources element that can declare multiple source entries, each with its own scope and directory.
<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 (mvnup)
The mvnup command analyses the existing POM, plugins, and project structure, then generates actionable migration suggestions.
mvnup check # only generate a report
mvnup apply # automatically apply the changesSigned-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.
