eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

eBook – Maven – NPI (cat=Maven)
announcement - icon

Get up to speed with the core of Maven quickly, and then go beyond the foundations into the more powerful functionality of the build tool, such as profiles, scopes, multi-module projects and quite a bit more:

>> Download the core Maven eBook

1. Overview

Maven has powered the Java build ecosystem for nearly two decades. Maven 3 appeared in 2010, and the community has awaited a major update since. Now, Maven 4 brings better performance, clearer model semantics, improved extensibility, and modern dependency resolution.

In this article, we explore the key changes in Maven 4. We show new features and provide code samples. We can find more details in the Maven Documentation.

In this article, we rely on Maven 4 RC5 as our reference version. At the time of writing, the Apache Maven project has not announced a final GA release date for Maven 4. Because of that, we base all examples and explanations on the most recent release candidate available. We need to declare the 4.x beta versions of the default plugins (esp. maven-compiler-plugin, maven-install-plugin, and maven-deploy-plugin) explicitly, because the RC does not provide them as default versions.

2. Model Version 4.1.0

Maven 4 updates the POM version to 4.1.0. It is compatible with version 4.0.0, but adds elements and marks some elements as deprecated.

The POM now looks like this:

<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>

We could omit the modelVersion element since Maven derives it from the schema.

Updating existing projects is optional. Maven 4 can build projects with version 4.0.0 or 4.1.0, but new features only work with the updated version.

3. Build/Consumer Separation

With Maven 3, a library’s POM includes build metadata like plugin configurations. This bloats dependency resolution and exposes internal details.

Maven 4 separates the Build POM from the Consumer POM. We keep the Build POM as before, and Maven generates a Consumer POM for dependency users.

A Consumer POM excludes build-specific info, parent POM references, and unused dependencies. It only includes transitive dependencies and managed dependencies that the project uses. Properties are resolved in place.

We call the transformation “flattening”. Maven 3 required the Flatten Maven Plugin, but the new versions of the Maven Install and Deploy plugins handle it natively when we use this command-line option:

mvn \
  clean install \
  -Dmaven.consumer.pom.flatten=true

4. New Artifact Types

For dependencies, we could specify a <type> to reference artifacts with non-default packaging. Maven defines several types in the Default Artifact Handlers Reference.

For a normal JAR, Maven adds it to the classpath. If the JAR contains module-info.class, Maven adds it to the module path, assuming that we use Java Modules. Maven 4 adds <type>classpath-jar</type> and <type>module-jar</type> to control this explicitly.

We also get new types to simplify annotation processor registration: processor, classpath-processor, and modular-processor. We just add dependencies instead of configuring plugins such as the maven-compiler-plugin.

For example, with Lombok and Maven 4, we could write:

<project>

  <properties>
    <lombok.version>1.18.42</lombok.version>
  </properties>

  <dependencies>
    <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>
  </dependencies>

</project>

We need both dependencies because Maven 4 separates API and processor classpaths.

In future releases, Maven might extend the list of types, e.g., for extending the taglet or doclet path.

5. Subprojects

Maven Modules got confusing when Java 9 introduced Java Modules. As a consequence, Maven 4 renames the term Modules to Subprojects. We now have a subprojects element in the POM, while the modules element is marked as deprecated:

<subprojects>
    <subproject>project-a</subproject>
    <subproject>project-b</subproject>
</subprojects>

And there are some other improvements:

  • Parent Inference: We can use an empty parent element with no coordinates. Maven infers it from the Aggregator POM.
  • Subprojects Discovery: We can omit the subprojects element, and Maven finds all subfolders with a pom.xml.
  • Consistent Timestamps in packaged archives for all subprojects
  • Safe Deployment: If one subproject fails, the others are not deployed to the repositories either.

6. Lifecycle Improvements

Maven 4 introduces a tree-based lifecycle. Each project moves through phases independently, and dependent projects start once dependencies reach their ready phase. This boosts performance for multi-project builds. We enable it with:

mvn -b concurrent verify

Each phase now has before: and after: hooks. These replace older pre- and post-phases, which are now aliases for backwards compatibility. For example, maven-gpg-plugin:sign can bind to before:install instead of verify, which would be semantically correct. after: hooks only run if the main phase succeeds.

Maven 4 also adds all and each phases with hooks. These help us run logic once per project tree or around each phase, making multi-project builds more predictable.

7. Further Changes

Some smaller changes affect upgrades:

  • Activating a non-existing profile with -PmyProfile fails. Use -P?myProfile to make the profile optional and avoid failure.
  • We can use –fail-on-severity or -fos to fail builds at a log level.

We now look at a few more changes that improve Maven 4’s flexibility.

7.1. Condition-Based Profile Activation

Maven 4 adds a condition element for profile activation. This allows us to declare complex expressions using functions:

<project>

  <!-- ... -->

  <profiles>
    <profile>
      <id>conditional-profile</id>
      <activation>
        <!-- use <condition><![CDATA[...]]></condition> to avoid encoding XML entities -->
        <condition>exists('${project.basedir}/src/** /*.xsd') &amp;&amp; length(${user.name}) > 5</condition>
      </activation>
      <!-- ... -->
    </profile>
  </profiles>

</project>

7.2. Source Directories

In Maven 3, we declare custom source roots with two dedicated elements. This works, but it is limited when we want multiple directories or fine-grained filtering:

<project>
  <!-- Maven 3 -->
  <build>
    <sourceDirectory>my-custom-dir/foo</sourceDirectory>
    <testSourceDirectory>my-custom-dir/bar</testSourceDirectory>
  </build>
</project>

Maven 4 introduces a unified sources section. We can list as many source roots as we need, assign a scope, and prepare more advanced setups without extra plugins:

<project>
  <!-- Maven 4 -->
  <build>
    <sources>
      <source>
        <scope>main</scope>
        <directory>my-custom-dir/foo</directory>
      </source>
      <source>
        <scope>test</scope>
        <directory>my-custom-dir/bar</directory>
      </source>
    </sources>
  </build>
</project>

This new model scales well for multi-release projects, module-based layouts, and cases where we want to apply include or exclude rules directly in the POM.

8. Maven 4 Upgrade Tool

Maven 4 adds an Upgrade Tool to migrate projects from Maven 3. It scans POMs, plugins, and structure, then recommends updates.

We can run it with:

mvnup apply

If we only want to get a report of what changes the tool suggests, without modifying pom.xml, we could do a dry run:

mvnup check

9. Conclusion

In this tutorial, we have learned that Maven 4 modernizes Java builds with a clearer POM model, separated build and consumer artifacts, and better support for modules and annotation processors. The updated lifecycle improves multi-project and concurrent builds. Hooks give us precise control, and smaller changes improve reproducibility.

The Upgrade Tool eases migration from Maven 3. Overall, Maven 4 boosts performance, clarity, and maintainability, laying a solid foundation for modern Java projects.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (All)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

eBook Jackson – NPI EA – 3 (cat = Jackson)