问题描述
默认情况下, gradle.user.home
设置为〜/.gradle
-我想将其更改为相对于项目的目录,而不是开发者的主目录.
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.
我知道您可以在调用gradle时这样做,就像这样:
I know you can do so when you invoke gradle, like so:
$ gradle --gradle-user-home=./project-relative-directory
或
$ gradle -Dgradle.user.home=./project-relative-directory
我知道您可以更改构建缓存的位置,方法是在settings.gradle中添加以下内容:
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"
}
}
但是gradle继续使用 gradle.user.home
进行其他缓存.
But gradle continues to use gradle.user.home
for other caching.
手册声明可以指定 gradle.user
,如下所示: gradle.properties
中的.home
The manual claims that you can specify gradle.user.home
in gradle.properties
, like so:
systemProp.gradle.user.home=./project-relative-directory
但是,对于绝对路径或相对路径,这似乎根本不起作用.尽管以后可能会通过 System.get
对其进行检索,但是 gradle
似乎并未利用它.
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.
还有其他解决方案吗?
推荐答案
当Gradle解析 gradle.properties
文件时,已经发生了太多事情.因此,使用自定义Gradle主页的唯一方法是通过具有最高优先级的命令行标志或通过系统属性.
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.
这篇关于gradle.user.home-在gradle.properties,build.gradle或settings.gradle中设置为相对于项目的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!