42

I see the following info in Eclipse package explorer:

enter image description here

Is it possible to change this location?

Dims
  • 47,675
  • 117
  • 331
  • 600

5 Answers5

67

Globally you can set

[...] Gradle user home directory (defined by the “GRADLE_USER_HOME” environment variable, which [...] defaults to USER_HOME/.gradle) [...]

See also https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_properties_and_system_properties.

Otherwise for every build manually:

-g, --gradle-user-home Specifies the Gradle user home directory. The default is the .gradle directory in the user's home directory.

See https://gradle.org/docs/current/userguide/gradle_command_line.html.

Andreas Schmid
  • 1,195
  • 8
  • 13
  • The first link isn't working anymore. Information about the Gradle user home directory can be found here: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_properties_and_system_properties – natronite Sep 16 '16 at 13:07
  • I have a user home -- May I also put the Caches some place else like a `tmp` drive? – will Jun 27 '17 at 06:02
  • Note: If you're running `gradle` or `./gradlew` commands in a CI/CD pipeline, using a `yml` file, you must use `export GRADLE_USER_HOME="/path/to/folder"` . The `export` command is important, to ensure that the environment variable is available to all scripts and sub-scripts that Gradle uses. – Mr-IDE Nov 11 '22 at 19:10
  • finally a normal answer, for all projects I hope it will work – user924 Apr 18 '23 at 11:45
16

You can change the cache location since gradle 3.5. This is controlled in settings.gradle file for your project:

buildCache {
    local {
        // Set local build cache directory.
        directory = "${settingsDir}/build-cache"
    }
}

thanks to Hubert Klein Ikkink, a.k.a. mrhaki.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • why build-cache? here says ".gradle": https://developer.android.com/studio/intro/studio-config#antivirus-impact – David Aug 21 '19 at 09:52
  • 2
    This cache location is controlled by the script, for specific project. I chose to name this directory `build-cache`, you are free to use name `the-best-directory-in-town`. Only be careful if the path has spaces, some tools may misbehave. – Alex Cohn Aug 21 '19 at 16:01
  • 1
    This answer conflates the *build cache* and the *dependency cache*. This question is about the *dependency cache*, which is where dependencies are stored locally when resolved. However, this answer is about the *build cache* which is where build outputs are stored and is usually disabled unless it's [explicitly been enabled](https://docs.gradle.org/current/userguide/build_cache.html#sec:build_cache_enable). – jr. Jul 15 '22 at 10:45
  • this is for one project. the question - for all projects automatically use specified gradle cache path? what you answered I can with Android Studio interface, no need to configure gradle. but Studio also sets it for the project only – user924 Apr 18 '23 at 11:44
5

You can change the location of gradle cache location in eclipse by setting the eclipse gradle preference

In Eclipse open, window-> preferences Search for 'Gradle' set 'Gradle User Home' to your preferred location Click Apply/ok

Now for the changes to take effect, you might have to do Gradle-> Refresh Gradle Project

Zack
  • 51
  • 1
  • 4
2

You can't change the location of the cache specifically, but you can change the Gradle user home directory (the .gradle directory) which the cache is located in by using the -g command line argument.

Mark Vieira
  • 13,198
  • 4
  • 46
  • 39
2

What worked for me was to edit my Windows environment variables and add variable GRADLE_USER_HOME with value d:/.gradle. (Replace "d:/.gradle" with the path to your gradle home.) Then exit and restart Eclipse.

Don Smith
  • 473
  • 4
  • 10