m for mvnw – Running maven wrapper a more convenient way

Maven wrapper is a cool tool thing for running maven builds with the correct maven version. This introduces a script that is already known for gradle. Simply type m on the command line and run the maven wrapper. Even in case the wrapper is not in the current directory.

The script

When using gradle it’s suggested to use the gradle wrapper. It simply runs gradle in the correct version. And there is a maven wrapper that does the same for maven. But I haven’t seen that g script for maven at all.

So there it is:

Installation

In order to get the system to your environment it simply must be added to your path. Adding it to your path can be achieved by adding the script into a bin directory of your choice. For a user the ~/bin directory can be chosen. Otherwise an alias that references the script would be ok too.

E.g. for getting a ~/bin directory into your path add

to your .profile. Alternatively to your .bashrc when using bash or .zshrc for zsh.

Usage

When being in a maven project simply run

And you’re done.

In case you are in a subdirectory of your project. Simply run

And you’re done too.

Of course the directory must be the root maven project or a maven module in a multi module build.

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.