Groovy 格雷德尔抱怨说;没有这样的文件或目录;
我正在使用Android Studio和Gradle构建脚本 在我的Android项目的根目录下,有一个名为“other”的文件夹,在“other”文件夹中,有一个属性文件my.properties 在我的build.gradle中,我尝试访问我的.properties: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
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");