See Project.files(…) where you can use a Task as the source for a FileCollection
A
Task
. Converted to the task’s output files. The task is executed if the file collection is used as an input to another task
So a FileCollection has two pieces of information that Gradle uses
- Task dependencies
- The actual files
Gradle first uses task dependencies to determine the DAG which defines the task order. It only iterates the actual files under the hood during each task’s “UP-TO-DATE” check prior to task execution.
Many of Gradle’s file based configuration methods accept Object which you can pass a task instance.
So you can do the following and Gradle will create the task dependencies based on TaskInputs
task task1 {
outputs.dir "path/to/output"
doLast {
// create files in output dir
}
}
task task2(type:Copy) {
from task1
into "another/path"
}
task task3 {
inputs.files task2
doLast {
task2.files.each { println it }
}
}