'How to set gradle cache location?

I see the following info in Eclipse package explorer:

enter image description here

Is it possible to change this location?



Solution 1:[1]

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.

Solution 2:[2]

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.

Solution 3:[3]

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

Solution 4:[4]

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.

Solution 5:[5]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Alex Cohn
Solution 3 Zack
Solution 4 Mark Vieira
Solution 5 Don Smith