3

By default, gradle.user.home is set to ~/.gradle - I'd like to change it to a directory relative to the project, rather than the developer's home directory.

I know you can do so when you invoke gradle, like so:

$ gradle --gradle-user-home=./project-relative-directory

Or

$ gradle -Dgradle.user.home=./project-relative-directory

I know you can change the location of the build cache by adding the following to settings.gradle:

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

But gradle continues to use gradle.user.home for other caching.

The manual claims that you can specify gradle.user.home in gradle.properties, like so:

systemProp.gradle.user.home=./project-relative-directory

But this doesn't appear to work at all, not for absolute paths or relative paths; although it may be retrieved later via System.get, gradle doesn't appear to make use of it.

Are there any other solutions?

drew
  • 2,949
  • 3
  • 25
  • 27

2 Answers2

4

you can also do it by changing the GRADLE_USER_HOME env variable. In this case all files will be saved in the specified directory.

export GRADLE_USER_HOME=./project-relative-directory
Nazar
  • 91
  • 4
2

When Gradle parses gradle.properties file, too much has already happened. So the only way to use a custom Gradle home is through a command line flag, which has the highest precedence, or through a system property.

Note that the documentation indicates that and does not mention the ability to set that value inside a properties file.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43
  • 1
    I won't argue with the correctness of the answer, but the link only seems to say "gradle.user.home=(path to directory) Specify the Gradle user home directory", which suggests that the user may in fact set the user home directory. – drew May 29 '19 at 13:14