Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Main differences between Maven 3 and 4

Now that there is release candidate 2 of Maven 4.0.0 and things become more stable, I would like to know:

What are the main differences between Maven 3.x and 4.0.0 for Maven users (and Maven plugin developers)?

I tried to have a look at release notes and the Maven homepage, but I am a bit overwhelmed. A lot information is about the internal structure of Maven, and there is a huge number of issues in the issue tracker that are resolved, but I did find any good information that summarizes the main improvements and breaking changes.

like image 581
J Fabian Meier Avatar asked Sep 17 '25 23:09

J Fabian Meier


2 Answers

Main points are:

  1. Separation of build POM and consumer POM. The build POM gets a new model version, while the consumer POM, generated during the build, still uses 4.0.0
  2. Better handling of modules (now called subprojects), less duplication of version numbers.
  3. A new packaging type bom for Bills of Materials.
  4. Improved lifecycle which allows to handle things happening before and after certain phases.
  5. A Maven shell that allows faster execution of Maven commands.

See also https://maven.apache.org/whatsnewinmaven4.html, thanks to Karl-Heinz Marbaise for the link.

like image 169
J Fabian Meier Avatar answered Sep 21 '25 17:09

J Fabian Meier


The https://maven.apache.org/whatsnewinmaven4.html is the main source.
Note that it is not finalized before Maven 4.0 release.

I would summarize as follows:

  • Java 17 as minimum to run maven mvn/mvnd

  • concurrent builder ( not default, used by passing -b concurrent),
    this in turn enables lifecycle phases to be as tree vs as sequence as it was in maven 3 and still Maven 4.0 default for compatibility.

  • (maven) subprojects is new name for maven modules,
    in order not to confuse with Java modules,
    but you don't need to update your pom.xml

  • Note that maven model version was 4.0 in maven 3.x, that may cause some confusions

  • New model version 4.1 can optionally be used for:

    • packaging type: bom for BOMs - will mainly benefit developers and users of multi-components frameworks
  • All core plugins updated to 4.x version
    Note that maven was and still is recommending to specify exact every plugin version used, so upgrading existing project would need to updates those version in pom.xml, but what is usually takes longer is all secondary and "outside-The-Maven-Land" plugins to be updated and fully compatible with 4.x
    Some "(very) old Maven plugins that have not been updated to use the recommended APIs" will stop working, i.e. Maven 4.0 drops some outdated plugin support.
    But usually you should see warnings for those plugins,
    especially when running Maven 3.9.x

There is extensive guide on how to Migrate to Maven 4.

For existing projects it is recommend first using Maven 3.9.x and checking all plugins updates mvn versions:display-plugin-updates.

P.S. The answer will be updated after 4.0 is finally released. Usually around that time there are review in Internet giving highlights and example.

like image 32
Paul Verest Avatar answered Sep 21 '25 16:09

Paul Verest