Maven 4: what changes

Maven · Expert · 10 min

Maven 4 is the first major release in a decade; teams maintaining builds need to know what to adopt.

Maven 4 (released after a long 4.0 beta cycle) keeps Maven 3 POMs building but modernizes the core:

  • Model 4.1.0: a new POM schema. Children can omit the parent version and groupId, and <subprojects> replaces <modules> (both still work). Maven 3 users can keep model 4.0.0.
  • Build POM vs consumer POM: the POM you write (with ${revision}, parent relativePath, build plugins) is transformed on install/deploy into a lean consumer POM with resolved versions and no build details. This makes CI-friendly versions work without the flatten plugin.
  • Reactor improvements: modules resolve against each other from target/classes more reliably, so mvn verify works across modules without install; -r/--resume resumes a failed build automatically; -pl accepts :artifactId paths and the reactor validates missing modules.
  • Parallel and daemon: -T is more robust, and the mvnd daemon is being merged in.
  • Stricter and clearer: deprecated options and plugins fail or warn earlier (e.g. system scope, LATEST/RELEASE versions, missing plugin versions), and error messages are improved.
  • New API (org.apache.maven.api.*) for plugins and extensions, immutable and with proper lifecycle and session objects; the Maven 3 API is still supported for compatibility.
  • Requires Java 17 to run (projects can still target older bytecode).

Adoption path: upgrade the wrapper to a 4.x distribution, run the build, fix warnings about plugin versions and deprecated features, then migrate to model 4.1.0 and <subprojects> once all contributors are on Maven 4. Check plugin compatibility notes; most mainstream plugins already support Maven 4.

Example

<!-- Maven 4 POM using model 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 https://maven.apache.org/xsd/maven-4.1.0.xsd">
  <modelVersion>4.1.0</modelVersion>
  <groupId>com.acme</groupId>
  <artifactId>shop-parent</artifactId>
  <version>1.2.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <subprojects>                      <!-- replaces <modules> -->
    <subproject>core</subproject>
    <subproject>api</subproject>
  </subprojects>
</project>

<!-- api/pom.xml: parent version and groupId can be omitted -->
<project xmlns="http://maven.apache.org/POM/4.1.0">
  <modelVersion>4.1.0</modelVersion>
  <parent>
    <artifactId>shop-parent</artifactId>
  </parent>
  <artifactId>api</artifactId>
</project>

<!-- ./mvnw wrapper:wrapper -Dmaven=4.0.0   then:  ./mvnw verify  (no install needed across modules) -->

Remember

  • Model 4.1.0 adds <subprojects> and optional parent version/groupId
  • Build POM vs consumer POM makes ${revision} versions clean
  • Reactor builds work across modules without install
  • New immutable API for plugins; Maven 3 API still supported

Check yourself

  1. What is the consumer POM in Maven 4?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: maven.apache.org/whatsnewinmaven4.html