Usage
Wrapper scripts are a set of files that can be added to your Maven project.
If people want to build this project, they don't need to install Maven first.
Instead they can call the Maven wrapper script (like mvnw
/mvnw.cmd
), which will download and unpack Maven into their ${user.home}/.m2/wrapper/dists
folder.
It is also an easy way to let everyone build the project with the same Maven version.
The Apache Maven Wrapper Plugin makes it easier to add these wrapper scripts to your project.
The scripts work like this:
- download the maven-wrapper jar, if it is not available yet,
- the maven-wrapper.jar contains the code to download, install and run Apache Maven
Apache Maven Wrapper Distribution Types
There are 4 distribution types available:
-
only-script (default for new installations): the lite implementation of
mvnw
/mvnw.cmd
scripts will download the maven directly via wget or curl on *nix, or PowerShell on Windows, then exec/call the originalmvn
/mvn.cmd
scripts of the downloaded maven distribution. This type does not usemaven-wrapper.jar
norMavenWrapperDownloader.java
, only the wrapper scripts are required. -
script: With this type the scripts will try to download the scripts via wget or curl in case of Unix based system, or use Powershell in case of Windows
-
bin: With this type the maven-wrapper jar is already available in the
.mvn/wrapper
folder, so you don't have to rely on wget/curl or Powershell The downside is that the project will contain a binary file in the source control management system. -
source: Since Maven already requires Java to run, why not compile and run a classfile to download the maven-wrapper jar? This type comes with a
.mvn/wrapper/MavenWrapperDownloader.java
which will be compiled and executed on the fly.
The type can be specified with mvn wrapper:wrapper -Dtype={type}
, where {type}
is any of the types listed above.
When wrapper:wrapper
is run in a Maven module which contains a .mvn/wrapper/maven-wrapper.properties
file, then the distribution type of the existing Maven Wrapper is used for the execution of the goal.
This allows updating Maven Wrapper, without unintentionally changing the distribution type for an existing project.
You can still use -Dtype={type}
to change the distribution type for an existing installation.
Maven Version
By default the plugin will assume the same version as the Maven runtime (calling mvn -v
). But you can pick a different version.
You can call mvn wrapper:wrapper -Dmaven=x
, where x
is any valid Apache Maven Release (see Maven Central).
Another option is to adjust the distributionUrl
in .mvn/wrapper/maven-wrapper.properties
.
Debugging
The apache-maven-wrapper distributions all contains the mvnwDebug
-script for both Windows and Unix based operating systems.
This makes it possible to debug through Apache Maven, Maven Plugin or Maven Extension.
You can include these scripts by calling mvn wrapper:wrapper -DincludeDebug=true