Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect setting of M2_HOME or MAVEN_OPTS #99

Open
imagejan opened this issue Jul 16, 2024 · 2 comments
Open

Respect setting of M2_HOME or MAVEN_OPTS #99

imagejan opened this issue Jul 16, 2024 · 2 comments

Comments

@imagejan
Copy link
Member

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:

jgo/src/jgo/jgo.py

Lines 430 to 434 in 89d20d1

config.set(
"settings",
"m2Repo",
os.path.join(str(pathlib.Path.home()), ".m2", "repository"),
)

Maybe we can do something similar to handling the JGO_CACHE_DIR variable?

jgo/src/jgo/jgo.py

Lines 726 to 729 in 89d20d1

if os.getenv(jgo_cache_dir_environment_variable()) is not None:
cache_dir = os.getenv(jgo_cache_dir_environment_variable())
_logger.debug("Setting cache dir from environment: %s", cache_dir)
config.set("settings", "cacheDir", cache_dir)

Related: #57.

@ctrueden
Copy link
Member

ctrueden commented Dec 3, 2024

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.

@imagesc-bot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants