devhome icon indicating copy to clipboard operation
devhome copied to clipboard

MAVEN_OPTS not set correctly when relocating Maven

Open wasabii opened this issue 1 year ago • 7 comments

Dev Home version

0.1501.533.0

Windows build number

No response

Other software

No response

Steps to reproduce the bug

Move m2 directory using Dev Home

Expected result

MAVEN_OPTS should be used to override parameters sent to the JVM. However, it's just set to the new m2 directory path. But the JVM of course does not know how to just handle a path stuck into its args.

Actual result

Doesn't work. JVM fails to launch.

Included System Information

No response

Included Extensions Information

No response

wasabii avatar Jun 29 '24 14:06 wasabii

An example of how to use MAVEN_OPTS: set MAVEN_OPTS=-Duser.home=D:\home\userFoo\bin\maven.config.directory

However, Dev Home just sets it to D:\home\userFoo\bin, etc.

wasabii avatar Jun 29 '24 14:06 wasabii

But I also think probably M2_HOME or MAVEN_HOME are the correct variables to be used.

wasabii avatar Jun 29 '24 14:06 wasabii

M2_HOME or MAVEN_HOME

I don't think so. This should be the location of maven installation directory and it's not on Dev Drive.

xuanswe avatar Aug 22 '24 20:08 xuanswe

Well, it's the location of the local Maven user directory. Which is usually not the install directory. It's where the settings.xml file would live. Which by default puts the local repository (cache) next to itself.

wasabii avatar Aug 27 '24 14:08 wasabii

So, two options: move all the user settings to the location dev home describes (and use M2_HOME), or alter the settings.xml to change the path of the local repository. I do not think there is an env variable that specifically relocates the local repository, since it's described by the master settings.xml file.

wasabii avatar Aug 27 '24 14:08 wasabii

Yeah, settings.xml describes the default expression for <localRepository> as ${user.home}/.m2/repository

So you'd have to actually edit the settings.xml.

wasabii avatar Aug 27 '24 14:08 wasabii

The MAVEN_HOME environnement variable is used to configure where Maven is installed:

  • M2_HOME was for Maven 2, but it's been more than 10 years since Maven 3 is released, I believe we can ignore it
  • Installing Maven in Dev Drive might help to speed it up a bit, but that's not the most important setting to do.

The real issue for Dev Drive is to have the Maven repository cache in Dev Drive: this is where the librairies are stored, and that's where you'll gain from the extra I/O from Dev Drive. By default this Maven repository cache is set up in ${user.home}/.m2/repository/, and to have it configured inside Dev Drive, the normal way would be to set it inside your ${user.home}/.m2/settings.xml configuration file (see https://maven.apache.org/guides/mini/guide-configuring-maven.html for full details). Now what is being done here, with MAVEN_OPTS, is pretty smart: this is modifying the user's home directory for Maven, so that it points to Dev Drive. This would remove the need to modify the ${user.home}/.m2/settings.xml configuration file at the expense of creating this environment file, so I'm not sure it's worth it.

My recommendation would be to:

  • (Optional) Install Maven on Dev Drive, and point to it with the MAVEN_HOME environment variable
  • (Recommended) Modify the ${user.home}/.m2/settings.xml configuration file to point to Dev Drive, for example <localRepository>D://maven-repository</localRepository>

jdubois avatar Sep 23 '24 18:09 jdubois