Search code examples
javamavenjava-17

Minimum and maximum version of Maven compatible with Java 17


As of the title, I am searching the range of Maven versions that ensures compatibility with Java 17, but I can't find anything on web or in Maven documentation.


Solution

  • This question cannot be answered clearly. The reason is, that Maven is organized in plugins. And the plugins are responsible for executing the corresponding tools of the JDK and other tasks. For example:

    • maven-compiler-plugin: executes javac (or more specifically uses javax.tools.JavaCompiler by default).
    • maven-jar-plugin: assembles the .jar (it does that autonomously without using the jar command).
    • etc.

    It is also a common (and good) practice to have the plugin versions explicitly defined in the pom.xml.

    Since Java has been quite gentle regarding backwards compatibility of artifacts so far (that strategy seems to shift a bit for the sake of security) it is able to execute Maven releases from ages ago. So there are uncountable options of version combinations (actually the root cause is that Java lacks of shipping it's own proper build tool and does not have a default repo like nodejs has with npm - a gap that Maven and Gradle are filling up).

    At the same time Maven is very gentle regarding upwards compatibility of its plugins as long as the same model version is used (which has been version 3 for a long time now) and other dependencies are compatible, most importantly Plexus.

    For example you can run Maven and compile Java 17 sources using the oldest Maven 3 version available - which is 3.0, dating back to 2010. Even a modules-info.java is compiled correctly, because Java is responsible for it - not Maven. However this version has configured central repositories using http instead of https, which is rejected by the servers by now, but you could change that configuration of course.

    Supported features is another thing. For example the --release option added to javac with Java 9 is supported by maven-compiler-plugin from 3.6.x and newer (specified through maven.compiler.release). However even with Maven 3.0 you can use maven-compiler-plugin 3.10.1, which has been released 12 years later (it stops working with 3.11.0, though).

    Lets take another feature example: Java 9 Modules. There are still some Maven plugins, that do not fully support it, like the maven-shade-plugin. It can modify regular classes, but not a modules-info.class.

    Finally let me rephrase your questions to

    What is the oldest Maven version usable out of the box without configuration changes?*

    3.2.3

    Is it compatible with Java 17?

    Basically, yes

    Is it recommended to be used?

    Definitely, no

    What is the recommended version?

    The latest, 3.9.5*

    Do all Maven plugins around have a version fully compatible with the latest Java version?

    No. There will never be.

    * as the time of writing