Discussion
@otfrom
You can put the maven cache whenever you like as long as you have permissions on the directory. Just create a `.mavenrc` file. https://maven.apache.org/configure.html#mavenrc-file
@otfrom
I think you can override the location here: https://maven.apache.org/settings.html#simple-values
But I'm mostly a #gradle user so I not that familiar with the #maven side of things
The location is configurable in settings.xml:
<localRepository>/path/to/whatever/.m2/repository</localRepository>
And you can tell maven which settings.xml to use by specifying it on the commandline:
mvn --settings /path/to/settings.xml
@elricofmelnibone looks like that can only be set to a single directory rather than a PATH or LD_LIBRARY_PATH like list?
It would be good to say something like "look in /usr/local/m2 then in ~/.m2"
@otfrom You can configure which repositories you publish to and which you resolve artifacts from on a per pom.xml-basis, where you can declare <repository>-objects. You <url>file:///path/to/wherever</url> to specificy paths on disk.
If you specify multiple repositories in this way, the order of precedence is specified here: https://maven.apache.org/guides/mini/guide-multiple-repositories.html
@elricofmelnibone ooh, thank you. I think this is what I was looking for
@otfrom @elricofmelnibone if there were multiple levels, how would you want it to decide which one to write new artifacts to?
@fae @elricofmelnibone I probably need to understand more about guix and nix as well, but I'm trying to think about how to make ~/.m2 play nicely with system wide dependencies installed by the distros package manager so that things can be recreated. (which makes me think that the solution is a symlink to the right part of ~/.m2, but I should really read how the current nix/guix systems do it)
@otfrom@funct onal.cafe @elricofmelnibone from my limited experience packaging maven projects for nix, maven.buildMavenPackage actually creates a new maven cache (a .m2) for every build, since the hash of the mvn deps `mvnHash` is stored along side the hash of the src. so the collection of mvn dependencies for a given version of pom.xml is treated as a monolith.
i think this dedicated .m2 for the build might be recycled between builds if the hash does not change?
nix is many things, but it is not disk space efficient.
see example package configs at: https://ryantm.github.io/nixpkgs/languages-frameworks/maven/
@otfrom I have never seen a package manager from the OS writing to the maven repo directory. And I hope NIX does not do it as well.
Yes, but I'm struggling to understand, what problem you want to solve? Multi-level caching? If so, what's your concern with using one global or project specific caches?
Maven caches are usually much smaller than npm module caches, if that's your concern.
@otfrom yes, there is. You may want to look at your local repository configuration of the used maven configuration. See https://maven.apache.org/guides/mini/guide-configuring-maven.html
The maven configuration can be fetched from your local .m2 or the local maven installation AFAIK. Also check overrides in your pom.xml.