gradle.user.home - set in gradle.properties, build.gradle, or settings.gradle to a project-relative location?

自古美人都是妖i 提交于 2021-01-28 11:12:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/56350799/gradle-user-home-set-in-gradle-properties-build-gradle-or-settings-gradle-to

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!