19

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.

Naman
  • 27,789
  • 26
  • 218
  • 353
FatalError
  • 52,695
  • 14
  • 99
  • 116

2 Answers2

28

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.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • 1
    For those reading this answer: `3.2.5` is a shortcut to `[3.2.5,)` otherwise the plugin will restrict to 3.2.5 only. – Michael-O Oct 06 '15 at 18:41
  • @Michael-O Yes, this is specified in the [range specification](http://maven.apache.org/enforcer/enforcer-rules/versionRanges.html) of this plugin. – Tunaki Oct 06 '15 at 19:04
1

If you only need the maven version the prerequisites should already do the job:

see: https://maven.apache.org/pom.html#Prerequisites

Anything more than that will require the enforcer plugin (see other answer).

wemu
  • 7,952
  • 4
  • 30
  • 59