mavenmaven-enforcer-plugin

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.


Solution

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