I’ve encountered the need to install different versions of m2 (maven 2) simultaneously. That’s something you will probably never have to do, but maybe this little description will help you.
The basic idea is to use wrapper scripts that configure m2 to use different settings. Here’s a full explanation.
Background Information
m2 User Profile
m2 stores most of its information in your user profile. This directory, usually
${user.home}/.m2
contains in my case the following files:
settings.xml
repository/
My m2 Requirements
I fix the occasional bug in m2 and also test the latest trunk version for any regression with regard to my build. So I use both a stable m2 and a more unstable trunk version. Trying to mix m2-2.0-beta-3 and m2-2.0-beta-4-SNAPSHOT dependencies in my local repository resulted in issues and forced me to wipe out my local repository. Rebuilding this one took ages, so I decided to find a way to avoid having to do that again. Furthermore I really wanted to validate my builds from a clean build environment.
The Setup
So I decided to have a parrallel install of m2 beta-3 and m2 trunk. The following setup is Linux specific. Should be pretty easy to adapt it to Windows.
- the settings.xml allows you to set the
<localRepository>. Unfortunately you cannot store this information in your <profile>. As one cannot yet use system properties in the settings file, we have to create 2 files, one for each installation
- m2 does not require M2_HOME/bin to be in the PATH.
Basics
Taking this into account, I have the following install:
> ls ~/.m2/
~/.m2/settings-m2b3.xml
~/.m2/settings-m2trunk.xml
~/.m2/directory-m2b3/
~/.m2/directory-m2trunk/
> echo $PATH
/usr/local/lib/java/bin:/home/jerome/local/bin:/home/jerome/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
> which m2
> which m2b3
/home/jerome/local/bin/m2b3
> which m2trunk
/home/jerome/local/bin/m2trunk
> cat `which m2b3`
export M2_HOME=/home/jerome/local/lib/maven-2.0-beta-3/
$M2_HOME/bin/m2 -s ~/.m2/settings-m2b3.xml $*
> head -2 ~/.m2/settings-m2*.xml
==> /home/jerome/.m2/settings-m2b3.xml < ==
<settings>
<localRepository>/home/jerome/.m2/repository-m2b3</localRepository>
==> /home/jerome/.m2/settings-m2trunk.xml < ==
<settings>
<localRepository>/home/jerome/.m2/repository-m2trunk</localRepository>
>
I.e. no m2 installed on the regular PATH, but a m2b3 and m2trunk wrapper scripts configured to use 2 different settings.xml files, each one configured to use a different localRepository
If one needs to have a m2 executable in the PATH, (I need one), one can add the following line to the wrapper script:
PATH=$PATH:$M2_HOME/bin
Installing The Trunk
Note: this only works with a m2 trunk taken from at least today (12 Oct 2005).
Thanks to MNG-1179 and MNG-1183 being fixed, one can now install the trunk in a new repository, without being forced to create a ~/.m2/settings.xml file (which I don’t use anymore)
First create this settings file for your trunk (in my case settings-m2trunk.xml).
Then build m2 using:
> export M2_HOME=/home/jerome/local/lib/m2-trunk
> export PATH=$PATH:$M2_HOME/bin
> ./m2-bootstrap-all.sh -s ~/.m2/settings-m2trunk.xml
Usage
I now invoke m2b3 or m2trunk depending on what I want to do.
I can update the m2 trunk without fear of having a broken builder. Of course, one needs a little bit more of disk space. When changing builder on the same project. a m2 clean:clean should be performed before any other action.
> du -sk ~/.m2/repository*
16452 /home/jerome/.m2/repository-m2b3
24140 /home/jerome/.m2/repository-m2trunk
Last Notes
Potential improvements: when MNG-942 is fixed, one will be able to do without having 2 different settings.xml file. This may turn both good (when both m2 versions are mostly identical, reuse is possible) or bad (if the structure of the settings.xml file has changed in a incompatible way, making it harder to reuse). Time will tell.