Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy 格雷德尔抱怨说;没有这样的文件或目录;_Groovy_Gradle_Android Gradle Plugin_Build.gradle - Fatal编程技术网

Groovy 格雷德尔抱怨说;没有这样的文件或目录;

Groovy 格雷德尔抱怨说;没有这样的文件或目录;,groovy,gradle,android-gradle-plugin,build.gradle,Groovy,Gradle,Android Gradle Plugin,Build.gradle,我正在使用Android Studio和Gradle构建脚本 在我的Android项目的根目录下,有一个名为“other”的文件夹,在“other”文件夹中,有一个属性文件my.properties 在我的build.gradle中,我尝试访问我的.properties: task accessMyProperties { def folderName = 'other'; //Gradle complains this line def file = new File

我正在使用Android Studio和Gradle构建脚本

在我的Android项目的根目录下,有一个名为“other”的文件夹,在“other”文件夹中,有一个属性文件my.properties

在我的build.gradle中,我尝试访问我的.properties:

task accessMyProperties {
    def folderName = 'other';

    //Gradle complains this line
    def file = new File("$folderName/my.properties");
    ...
}
但格拉德尔抱怨说:

* What went wrong:
A problem occurred evaluating project ':MyApp'.
> other/my.properties (No such file or directory)

gradle为什么会出现上述错误?如何摆脱它?

在Gradle构建脚本中使用纯相对路径时要小心;它们在调用构建时依赖于工作目录,这不是您应该依赖的。最好将路径与
$projectDir
$rootDir
进行比较。试着这样做:

def file = new File("$projectDir/$folderName/my.properties");
有关可使用的变量列表,请参阅

def file = new File("$projectDir/$folderName/my.properties");