0

For some reasons I have to use two different maven versions on my windows PC. I already had the maven 3.6.0 installed, working well.

Now I want to install maven3.1.1 and running it like that, for example :

3.1.1

mvnOld clean install

3.6.0

mvn clean install

So I did add in my windows system path the bin folder of the 3.1.1 and in this same folder I did rename files to match mvnOld

enter image description here

For some reasons it's not working, when opening a new CMD, mvnOld is still an unknow command.

What did I miss? Any better ways ?

ps: In those files there was $M2_HOME used, that I did replace with $M2_OLD_HOME that points out on my 3.1.1 folder.

Logan Wlv
  • 3,274
  • 5
  • 32
  • 54
  • You can only have one of them on the PATH. Separation via `M2_HOME` will not work cause it's not supported...and why do you need different Maven versions? Why not using Maven 3.6.0 only ? – khmarbaise Apr 17 '19 at 07:56
  • I have to build an old project, and the company strictly required me to use maven3.1.1 and not 3.6.0... but yeah I guess it could work with 3.6.0, but let's keep it to the original question. So it can not work in any ways ? – Logan Wlv Apr 17 '19 at 08:01
  • So I have to change my system variables each time I want to switch from 3.6.0 to 3.1.1 – Logan Wlv Apr 17 '19 at 08:02
  • 1
    Maybe this might be the right choice: https://sdkman.io/ – khmarbaise Apr 17 '19 at 08:09

2 Answers2

1

Your approach is very brittle.

I know the problem: For building Nexus 2.x plugins, you can only use Maven 3.0.4 or Maven 3.0.5.

I did not put the old Maven on the path but used Eclipse to solve the problem: For the Nexus plugin project, I set the old Maven.

If you need to use command line, you can just use the full qualified name for the old Maven.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Didn't think about building it with Eclipse, it should work in my case ! When you say full qualified name you mean calling the command with anyPath/maven3.1.1/bin/mvn clean install (for example) ? – Logan Wlv Apr 17 '19 at 09:15
  • Yes. In Eclipse, you can use "Run As -> Maven build ... " and then choose the Maven from the list (if it is missing ,you need to add it first) – J Fabian Meier Apr 17 '19 at 12:01
  • The Eclipse solution is working, but for the full qualified name I do not understand how it could work with Windows. First in the mvn file you can see it is reading on your M2_HOME variable, so we should change it to the correct folder. And it's not an executable so how could it be runned ? Could you add some details for the commandline part ? – Logan Wlv Apr 17 '19 at 12:18
  • I'll validate your answer anyway, since using Eclipse worked for me. But I do not understand the command line part – Logan Wlv Apr 17 '19 at 12:18
  • The `mvn.cmd` in your Maven is a executable command. You can run it giving the full path. – J Fabian Meier Apr 17 '19 at 12:24
0
  1. Delete Win System Variables M2_HOME;

  2. Don't put two version maven files in same folder and don't rename the file;

  3. Edit apache-maven-3.1.1\bin\mvn.cmd:add M2_HOME before "START VALIDATION"

    set M2_HOME=D:\apache-maven-3.1.1

  4. Edit apach-maven-3.6.0 mvn.cmd as same way

  5. Run it giving the full path,

    D:\apache-maven-3.1.1\bin\mvn --version D:\apache-maven-3.6.0\bin\mvn --version

leeyue
  • 1