2

I need do mention about Gradle to understand and find the same solution for Maven.

In Gradle exists the GRADLE_HOME and GRADLE_USER_HOME (repository) environment variables, for Maven the former through M2_HOME and about the repository I use the settings.xml file to define the <localRepository> location

For both Maven and Gradle I can define in peace the place about where is installed the software, for example other location than .m2 and .gradle to a secondary disk and even with customized directory names. Same goal about the repository location, both for a secondary disk (remember for Maven through the settings.xml file)

Note: therefore .gradle and .m2 are empty and not used.

In Gradle about the wrapper created, the gradle-wrapper.properties file has:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-#.#.#-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Then the final path is: GRADLE_USER_HOME/wrapper/dists Therefore observe how GRADLE_USER_HOME (custom location - otherwise .gradle by default) is used to define the:

  • Local repository
  • Base path to install the downloaded Gradle through the wrapper

Goal: How accomplish the same behaviour for Maven? I mean, what should be the environment variable name (something like MAVEN_USER_HOME) for the local repository that Maven should recognize automatically? (not using the settings.xml file). It with the purpose to have any Maven wrapper installed according that environment variable name configured (custom location - otherwise .m2 by default) and of course defined the Local Repository too.

Therefore: I need the maven-wrapper.properties using something like MAVEN_USER_HOME (custom location - otherwise .m2 by default) according the developer/user in its machine.

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
  • What is the advantage of *not* using the default place `.m2` in the user directory? – J Fabian Meier Dec 08 '20 at 19:28
  • Have a customized location, and the case the primary disk is running out of space too, is possible have the Local Repository and wrappers distributions in other place from the beginning (pendrive with a high capacity). – Manuel Jordan Dec 08 '20 at 19:36
  • As IO is the main factor in the build, I would put my local repository on an SSD. – J Fabian Meier Dec 08 '20 at 19:38
  • Agree, consider a SSD too, the point is define a different location than the primary disk. – Manuel Jordan Dec 08 '20 at 19:43
  • 2
    I have the exact same query as Jordan. I feel that we should answer straight to the point, whether what Jordan asks can or cannot be done, rather than asking him for the advantage, or where he should put the local repository. Cos if he is ask this question, he definitely has his own reason for not using the default directory. Even if we convince him that there is no advantage in changing the default place, still it is good to know if Maven has such any constraint in terms of using environment variable to control the local repository location, at least from learning point of view. – Nick Wills Jan 06 '21 at 15:05

1 Answers1

2

For me, I am using spring boot boilerplate code that is generated from spring.io. Inside come with mvnw.cmd. By setting MAVEN_USER_HOME to a customized location, running mvnw.cmd will download the maven to that customized location.

Once done, I still need to manually go to that downloaded maven location to configure the settings.xml to point to a customized location for the maven libraries repo.

So at the moment, sadly, seem like the settings.xml is required to configure the repo, and MAVEN_USER_HOME environment variable has nothing to do with the repo.

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
Nick Wills
  • 800
  • 2
  • 10
  • 26