Is it possible to specify in a POM the minimum version of Maven required to build the project?
We've been wasting lots of time chasing issues from people building our project due to bugs in older versions of Maven that cause large artifacts (>2GB) to be silently truncated. These tend to cause, unsurprisingly, strange and broken behavior in the final product.
Yes, we have stated that 3.2.5 is the minimum version we intend to support, but I'm wondering: Is there a way to ask Maven to bail if the version is less than that? I reckon I can easily write a plugin to do this, but that seems overkill. So, I was hoping there is a simpler way.
Maven won't allow any other either. Build will fail if version is not found.
1 for LTS) requires Java 8 thus Maven jobs must be launched with a JDK >= 8. Soon (July-September 2022 timeframe) Jenkins will require Java 11 thus Maven jobs must be launched with a JDK >= 11.
Maven Enforcer Plugin - The Loving Iron Fist of Maven™ The Enforcer plugin provides goals to control certain environmental constraints such as Maven version, JDK version and OS family along with many more built-in rules and user created rules.
Setting the Maven versionAdd an environment variable to your development system called ATLAS_MVN. Set the value of ATLAS_MVN to your Maven executable. Keep in mind this should be the Maven executable, not the Maven home. Verify the configuration by running the atlas-version command.
You can use the maven-enforcer-plugin
and its enforce
goal to specify a minimum required Maven version:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.2.5</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
If someone tries to build the project with a Maven version less than 3.2.5, the build will fail.
You can enforce a lot of different rules with this plugin (Java version, OS...); see the complete list on the plugin documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With