It will allow to switch easily between multiple maven versions.
After you install mvnenv, when you run the command "mvn" a script in mvnenv's bin directory will be executed it will check the configuration, automatically set M2_HOME to the desired maven installation and MAVEN_OPTS to the desired option and finally execute the mvn command.
Tested on Mac OS X (10.9.2)
-
Check out mvnenv into
~/.mvnenv
.$ git clone https://github.com/themnd/mvnenv.git ~/.mvnenv
-
Add
~/.mvnenv/bin
to your$PATH
.$ echo 'export PATH="~/.mvnenv/bin:$PATH"' >> ~/.bash_profile
JENV note
if you use jenv (http://www.jenv.be) make sure the "export PATH" command in point 2 is placed before eval "$(jenv init -)"
MAVEN note if maven bin is present in $PATH it must be listed AFTER mvnenv! you can remove maven bin from $PATH, since the "mvn" (and "mvnDebug" and "mvnyip" are automatically handled by mvnenv).
-
Add
mvnenv init
to your shell.$ echo 'eval "$(mvnenv init)"' >> ~/.bash_profile
-
Start a new shell.
$ source ~/.bash_profile
-
Verify that mvnenv works.
$ mvnenv --version
-
Add the needed maven versions.
$ mvnenv add /path/to/maven2 $ mvnenv add /path/to/maven3
for example mvnenv add /opt/local/share/java/maven2
-
Configure which maven version to use.
Globally
~~~ sh
$ mvnenv global maven2
~~~
*In this directory*
~~~ sh
$ mvnenv local maven2
~~~
*In the current shell*
~~~ sh
$ mvnenv shell maven2
~~~
-
Verify that works.
$ mvn -version
This is the list of available commands. Normally when a command raise an error it will also set the exit code to 1.
Display the current mvnenv version.
Add a maven installation to the list of available versions.
$ mvnenv add /opt/local/share/java/maven3
install /opt/local/share/java/maven3 as maven3
do install
in case that version was already added:
$ mvnenv add /opt/local/share/java/maven3
install /opt/local/share/java/maven3 as maven3
already installed
Display the maven version that will be used.
$ mvnenv current
Using global version maven3
Using global version maven3
Using global option -Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Djava.awt.headless=true
Without parameters will show you which version is used for global.
$ mvnenv global
Current global mvn version
maven3
Available:
maven2
maven3
maven311
With the name of a version will set that version as the global one.
$ mvnenv global maven2
Without parameters will show you if there is any global option set.
$ mvnenv global options
Current global mvn option: -Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Djava.awt.headless=true
or
$ mvnenv global options
There is no global mvn option set
You can set a specific global option (the --set parameter is optional).
$ mvnenv global options "-Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Djava.awt.headless=true"
setting option: [-Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Djava.awt.headless=true]
And you can unset the current global option:
$ mvnenv global options --unset
Removed global mvn option: -Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Djava.awt.headless=true
if set the MAVEN_OPTS environment variable have always the precedence over global options
This command is only used in the .bashrc | .bash_profile to setup the other commands, you must have this in your init script:
eval "$(mvnenv init)"
This command allow you to set a specific version for the current directory, it does it by creating a file named .mvnenv_version in the current directory, this means that for subdirectories the global one will apply.
Without parameters will show you which version is used for local.
$ mvnenv local
Current local mvn version
maven3
Available:
maven2
maven3
maven311
With the name of a version will set that version as the local one.
$ mvnenv local maven2
You can remove the current local version by using --unset.
$ mvnenv local --unset
Removed local maven version
Without parameters will show you if there is any local option set.
$ mvnenv local options
Current local mvn option: -Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Djava.awt.headless=true
or
$ mvnenv local options
There is no local mvn option set
You can set a specific local option (the --set parameter is optional).
$ mvnenv local options "-Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Djava.awt.headless=true"
setting option: [-Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Djava.awt.headless=true]
And you can unset the current local option:
$ mvnenv local options --unset
Removed local mvn option: -Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Djava.awt.headless=true
if set the MAVEN_OPTS environment variable have always the precedence over local options
Remove a maven version from the list of available versions.
$ mvnenv remove maven3
This command allow you to set a specific version for the current shell.
Without parameters will show you which version is used for the shell.
$ mvnenv shell
Current shell mvn version
maven3
Available:
maven2
maven3
maven311
With the name of a version will set that version for the current shell.
$ mvnenv shell maven2
You can remove the current shell version by using --unset.
$ mvnenv shell --unset
Removed shell maven version
List the available maven versions that have been added with the add command.
$ mvnenv versions
maven2
maven3
maven311
Please feel free to submit pull requests and file bugs on the issue tracker.
Heavily inspired by https://github.com/gcuisinier/jenv
Thanks to https://blog.jcoglan.com/2013/02/12/tab-completion-for-your-command-line-apps for explaining clearly how autocomplete works.