How to use the Maven wrapper in your projects

What is the shell script mvnw in your project directory?
The Maven Wrapper is a simple way to run Maven on your machine, without manual installation of Maven.

Why should we use that? Maven has been avery stable for users, and it is quite simple to install: however, due to many of the recent changes in Maven it will be easier for users to have a fully encapsulated build setup provided by the project. With the Maven Wrapper this is very easy to do and it’s a great idea borrowed from Gradle.

The easiest way to setup the Maven Wrapper for your project is to use the Takari Maven Plugin with its provided wrapper goal. To add or update all the necessary Maven Wrapper files to your project execute the following command:

mvn -N io.takari:maven:0.7.7:wrapper

Note: The default usage should be mvn -N io.takari:maven:wrapper but for some users this seem to result in usage of an old version of the wrapper and therefore installation of older Maven defaults and so on.

Normally you instruct users to install a specific version of Apache Maven, put it on the PATH and then run the mvn command like the following:

mvn clean install

But now, with a Maven Wrapper setup, you can instruct users to run wrapper scripts:

./mvnw clean install

or on Windows:

mvnw.cmd clean install

A normal Maven build will be executed with the one important change that if the user doesn’t have the necessary version of Maven specified in .mvn/wrapper/ it will be downloaded for the user first, installed and then used.

Subsequent uses of mvnw/mvnw.cmd use the previously downloaded, specific version as needed.