I have several different projects that, because of the toolchain they use, use different versions of the exact same dependencies on different versions of Gradle each mapped in different ways. These ways are not compatible with each other, but since Gradle always checks the global cache first, it keeps finding the unusable versions of the dependencies it’s looking for. I find myself having to delete my global
.gradle cache and force-redownload everything every time I switch projects.
Is there any way to tell Gradle “screw the global cache, cache the dependencies in the project folder” like in NPM?
Can you provide a concrete example with MCVE?
From what you wrote, at least I cannot understand what problem you actually have.
The details are all fairly irrelevant to the question. Basically, is there any way to make Gradle cache my dependencies locally (i.e. in
Project/.gradle/caches/ instead of globally (i.e.
I make mods for an obfuscated platform, and use a deobfuscation mapper to convert the obfuscated names into their deobfuscated names. The platform I work on also lets me transform the access modifiers of some fields in the source code, generating different versions of the source jar with these access transformers applied. This poses a problem when everything is cached globally, as I have multiple versions of the same source jar with different access modifiers applied.
accesstransformer = file("at_1.cfg")
implementation mapper.map('platform:mainjar') // Mapped with the access transformer at_1.cfg
accesstransformer = file("at_2.cfg")
implementation mapper.map("platform:mainjar") // Reads the main jar from the global cache, which is mapped with at_1.cfg instead of at_2.cfg
This occurs for all of my dependencies mapped with the deobfuscation mapper. It’s also exacerbated by the fact that I have to use different versions of the same plugin to compile it properly on different projects due to a lack of support from the devs.
No, the details are exteremly relevant.
You should never ever modify the jars in the cache in any way ever, ever.
This way you break the cache even if it were local in the project directory.
You can have the complete Gradle user home at a different location by using a system property, an environment variable, or a command line argument.
But as I said, even then you should never ever modify the jars in the cache.
For such ad-hoc transformations Gradle has support for exactly that called “Artifact Transform” where you can in a safe way apply transformations to incoming artifacts and these transformations can even be made cacheable.
I am not writing a new plugin here; I don’t need this information. I am using an existing plugin that likely already does what you are talking about, and is also literally the only way to build for my target platform. These details are not relevant to me, as I physically cannot change them even if I wanted to.
Is there a way to make Gradle cache dependencies - for my project specifically - in a location that I set, without modifying the global Gradle home? For example: by defining a local Gradle home in my
build.gradle if it is native functionality, or using another plugin if it exists, or even making a process-specific symlink or modifying
/etc/hosts or literally any stupid hack possible that will accomplish this specific issue that I am asking about.
I am using an existing plugin that likely already does what you are talking about
Obviously it is not doing what I say or the different projects wouldn’t influence each other.
What you describe can only happen if the cached jars are modified in-place which is a big no-go.
If that plugin does that, you should strongly consider not to use it until it fixed that non-sense or patch it so that it does it properly.
Is there a way to make Gradle cache dependencies - for my project specifically - in a location that I set, without modifying the global Gradle home?
Depends on what you mean by “global” and whether you mean “Gradle User Home” when you say “Gradle Home” (the latter is where the Gradle installation is, the former where the caches and so on are.
If you only change the Gradle User Home for that project, it is not the “global” one.
If you meant to only change the cache location, I don’t think so, either you change the whole Gradle User Home for that project or you don’t.
For example: by defining a local Gradle home in my
Within the build script is way too late.
I already told you can change it using a system property, an environment variable, or a command line argument.
You can do this for example by using a wrapper script that sets it, or by setting