Respect setting of M2_HOME or MAVEN_OPTS
jgo (at least when launched via Python: python -m jgo) currently doesn't respect when the environment variables M2_HOME or MAVEN_OPTS are set.
We currently default to this:
https://github.com/scijava/jgo/blob/89d20d1167e40784b6f1f185e55face10df74318/src/jgo/jgo.py#L430-L434
Maybe we can do something similar to handling the JGO_CACHE_DIR variable?
https://github.com/scijava/jgo/blob/89d20d1167e40784b6f1f185e55face10df74318/src/jgo/jgo.py#L726-L729
Related: #57.
I've been digging into this. Independent of jgo, here's what doesn't work:
- Setting
M2_REPOdoes not seem to be picked up bymvnon the command line, nor doesM2_HOME. - Passing
-Dmaven.repo.local=/path/to/somewhereand/or-Dmaven.home=/path/to/another/placedirectly tomvnalso does not work to override those locations. - Setting
MAVEN_OPTS=-Dmaven.home=/home/curtis/.m3does not do anything—i.e. it ignores both~/.m3/settings.xmland~/.m3/conf/settings.xml, despite the documentation suggesting that it should read one or both of these files whenmaven.homeis set.
And here's what does work:
-
Setting
MAVEN_OPTS=-Dmaven.repo.local=/path/to/somewhereoverrides the local repository location:$ export MAVEN_OPTS=-Dmaven.home=/home/curtis/.m3 $ maven-echo 'maven.home=${maven.home}, maven.repo.local=${maven.repo.local}' maven.home=/usr/share/maven, maven.repo.local=${maven.repo.local} # ^ fail $ export MAVEN_OPTS=-Dmaven.repo.local=/home/curtis/.m3/repo $ maven-echo 'maven.home=${maven.home}, maven.repo.local=${maven.repo.local}' maven.home=/usr/share/maven, maven.repo.local=/home/curtis/.m3/repo # ^ success -
Passing
-s mysettings.xmldirectly tomvnwill override the local repository location (although does not populate themaven.repo.localsystem property), as long as thatmysettings.xmlfile has a line like<localRepository>/home/curtis/.m3/customrepo</localRepository>beneath its<settings>block.
On the jgo side, I haven't tested thoroughly yet, but looking at the code, it seems very unlikely that overriding the jgo.resolve_dependencies function's m2_repo parameter value is likely to do much good: all that value is used for is from where to link the downloaded dependencies. In particular: it does not actually instruct mvn to download and cache the dependencies to that location, but only assumes they will be put there when looking for them afterward.
So to fix this properly, I guess we need to change jgo to build a settings.xml with the desired localRepository, write it into the currently-being-built environment directory, then pass that file path to mvn via its -s flag when doing the dependency resolution.
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/fiji-friends-weekly-dev-update-thread/103718/31