jgo icon indicating copy to clipboard operation
jgo copied to clipboard

Respect setting of M2_HOME or MAVEN_OPTS

Open imagejan opened this issue 1 year ago • 2 comments

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.

imagejan avatar Jul 16 '24 09:07 imagejan

I've been digging into this. Independent of jgo, here's what doesn't work:

  • Setting M2_REPO does not seem to be picked up by mvn on the command line, nor does M2_HOME.
  • Passing -Dmaven.repo.local=/path/to/somewhere and/or -Dmaven.home=/path/to/another/place directly to mvn also does not work to override those locations.
  • Setting MAVEN_OPTS=-Dmaven.home=/home/curtis/.m3 does not do anything—i.e. it ignores both ~/.m3/settings.xml and ~/.m3/conf/settings.xml, despite the documentation suggesting that it should read one or both of these files when maven.home is set.

And here's what does work:

  1. Setting MAVEN_OPTS=-Dmaven.repo.local=/path/to/somewhere overrides 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
    
  2. Passing -s mysettings.xml directly to mvn will override the local repository location (although does not populate the maven.repo.local system property), as long as that mysettings.xml file 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.

ctrueden avatar Dec 03 '24 20:12 ctrueden

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

imagesc-bot avatar Dec 09 '24 19:12 imagesc-bot