How to use multiple maven versions parallel


I need (two) different maven versions in my development system, a actual maven (2.2.1) for the „normal“ work and a tycho-maven for eclipse-osgi projects (i.e. m2eclipse).

Setup maven installations

The result should look like this:

multiple_maven_installation

multiple_maven_installation_tycho

Configure maven installations

The tycho maven in D:\maven-distro\maven-tycho\conf contains a settings-tycho.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>D:\maven-repos\maven-tycho</localRepository>
</settings>

and a settings.xml (this is the changed „standard“ maven configuration):

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/settings/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <profiles>
    <profile>
      <id>tycho-default</id>
      <repositories>
        <repository>
          <id>forge</id>
          <url> http://repository.sonatype.org/content/groups/public</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
          <releases>
            <enabled>true</enabled>
          </releases>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>forge</id>
          <url> http://repository.sonatype.org/content/groups/public</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
          <releases>
            <enabled>true</enabled>
          </releases>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>tycho-default</activeProfile>
  </activeProfiles>
</settings>

The standard maven in D:\maven-distro\maven-2.2.1\conf must not be changed. So this maven will use the default settings.xml and a user-settings from $HOME/.m2/settings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>D:\maven-repos\maven</localRepository>
</settings>

Configure development environment

I use cygwin under windows, so i can put the maven-tycho-alias into my ~/.bashrc:

# Add maven-tycho to path 
alias mvnTycho="tycho -s \"d:/maven-distro/maven-tycho/conf/settings-tycho.xml\""
export PATH="/cygdrive/d/maven-distro/maven-tycho/bin":$PATH

Usage

hoehmann@foobar /bin
$ mvnTycho --version
Apache Maven 3.0-TYCHO-797695 (r797704; 2009-07-25 04:43:26+0200)
Java version: 1.5.0_12
Java home: d:\java\jdk1.5.0_12\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"

hoehmann@foobar /bin
$ mvn --version
Apache Maven 2.2.0 (r788681; 2009-06-26 15:04:01+0200)
Java version: 1.5.0_12
Java home: d:\java\jdk1.5.0_12\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"

With this i can run mvn for „normal“ maven projects, this will start maven 2.2.1 from maven-distro/maven/ and the repo will be at maven-repo/maven/.

Or i can run mvnTycho for „osgi“ maven projects, this will start tycho from maven-distro/maven-tycho/ and the repo will be at maven-repo/maven-tycho/.

You can do this with much more versions (2.0.1, 2.1.0, 2.2.0) and each maven will have a own repository.

Try it🙂