Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforce a minimum version of Maven

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.

like image 944
FatalError Avatar asked Oct 06 '15 13:10

FatalError


People also ask

What happens if you don't specify a version in Maven?

Maven won't allow any other either. Build will fail if version is not found.

What is the minimum version of Java for Maven?

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.

What is Maven enforcer?

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.

How do I set the default version of Maven?

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.


1 Answers

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.

like image 99
Tunaki Avatar answered Sep 21 '22 03:09

Tunaki