Some of my projects have very large dependencies (several hundred MB), and I’d like to retrieve them only to the project directory, bypassing the default artifact cache (under ‘$GRADLE_HOME’). I’ve tried
gradle.startParameter.projectCacheDir = new File('projectCache')
in the project’s ‘settings.gradle’, but that doesn’t work as expected. Any guidance would be very much appreciated!
The ‘projectCacheDir’ is where project specific cache data is stored. Dependencies are stored in the dependency cache located in the gradle user home directory. You can also change this via ‘gradle.startParameter.gradleUserHomeDir’.
Thanks for the quick reply! Unfortunately, this doesn’t seem to have any effect at all, i.e., my ‘projectCache’ directory remains empty, while the dependency artifacts are downloaded into my ‘$HOME/.gradle/caches’.
If however I manually set the environment variable by running ‘GRADLE_USER_HOME=$PWD/projectCache gradle myTask’, then the dependencies are indeed downloaded into the project directory as desired. I would prefer to be able to somehow store this variable somewhere in the project, even if I have to modify the wrapper script, but nothing seems to work like manually exporting it on the command line…
Another unfortunate side-effect is that if I use the manually specified environment variable with the gradle wrapper script, the gradle distribution itself is also re-downloaded into the project directory…
It seems that modifying the ‘StartParameter’ instance from within a build won’t have any effect. The setters there are primarily for configuring a ‘GradleBuild’ task. Your only options are to set the environment variable to edit the wrapper scripts to pass a ‘-g’ command line argument.
You are correct though, the Gradle user home directory is used to cache all Gradle related items, to include downloaded wrappers. There is currently no way to designate just where you would like the Gradle artifact cache to reside.
Aha, thank you for the explanation!
Adding ‘-g’ to the wrapper script does work. Thank you!
Given that the wrapper has all those detailed options relating to where to download and unpack its distribution, it would be great to also allow easy customization of the dependency cache location, with the same access to the ‘PROJECT’ constant…