我正在尝试https://docs.gradle.org/current/userguide/working_with_files.html中的“示例24.实现文件集合”
我具有以下项目结构
├── build.gradle ├── settings.gradle ├── src │ ├── dir1 │ │ └── file11.txt │ └── dir2 │ └── file21.txt └── src2 ├── dir1 │ └── file211.txt └── dir2 └── file221.txt
build.gradle仅包含以下内容
task list {
doLast {
File srcDir
// Create a file collection using a closure
collection = layout.files { srcDir.listFiles() }
srcDir = file('src')
println "Contents of $srcDir.name"
collection.collect { relativePath(it) }.sort().each { println it }
srcDir = file('src2')
println "Contents of $srcDir.name"
collection.collect { relativePath(it) }.sort().each { println it }
}
}
当我执行“列表”任务时,抛出此错误。
我在做什么错了?
$ gradle -q list FAILURE: Build failed with an exception. * Where: Build file '/mnt/c/Users/.../temp/gradle-project-test/build.gradle' line: 13
更新:
似乎是gradle文档中的错字。下一行
collection = layout.files { srcDir.listFiles() }
必须更改为
def collection = layout.files { srcDir.listFiles() }