Gradle:我如何依赖资源任务对象?

Gradle:我如何依赖资源任务对象?,gradle,Gradle,在一个JavaWAR项目中,我有以下代码,例如,确保创建了一些目录 task resources << { mkdir "generated" } task acct(type: Exec) { dependsOn resources // ... } 如果我不使用引号,我想我正在使用一个任务实例(上面支持的列表中的第二项) 如果我在引号中使用“resource”,它会起作用。如果我将任务重命名为justres,它也可以在没有引号的情况下工作;依照 为什么

在一个JavaWAR项目中,我有以下代码,例如,确保创建了一些目录

task resources << {
    mkdir "generated"
}

task acct(type: Exec) {
    dependsOn resources
    // ...
}
如果我不使用引号,我想我正在使用一个任务实例(上面支持的列表中的第二项)

如果我在引号中使用
“resource”
,它会起作用。如果我将任务重命名为just
res
,它也可以在没有引号的情况下工作;依照


为什么会这样?建议用什么方式声明此依赖关系?

resources
将解析为
project.resources
。要引用任务,可以使用
tasks.resources
或(如您所说)
“resources”

为什么对待资源与res不同?因为存在
project.resources
属性(请参见中的
project
),但没有
project.res
属性。
Could not determine the dependencies of task ':acct'.
> Cannot convert org.gradle.api.internal.resources.DefaultResourceHandler@1d65e511 to
a task.
  The following types/formats are supported:
    - A String or CharSequence task name or path
    - A Task instance
    - A Buildable instance
    - A TaskDependency instance
    - A Closure instance that returns any of the above types
    - A Callable instance that returns any of the above types
    - An Iterable, Collection, Map or array instance that contains any of the above types