I've got a gradle build with a task like the following
task createFolders {
file(rootFolder).mkDirs()
}
Note that in the real system there are about 15 folders getting created during this task.
This task always reports as UP-TO-DATE when I run the task, even if I run it directly after deleted the folders being created. I have several tasks that depend on this task and they run.
How do I tell gradle that this task is only up to date if all the created folders exist?
Gradle builds are fast because Gradle supports incremental tasks. This means Gradle can determine if input or output of tasks has changed — before running the task. If nothing has changed, a task is marked as up-to-date and the task is not executed. Otherwise, the task is executed.
If the source code hasn't changed since the last compile, then it will check the output to make sure you haven't blown away your class files generated by the compiler. If the input and output is unchanged, it considers the task "up to date" and doesn't execute that task.
upToDateWhen { false } means “outputs are not up to date”. If any upToDateWhen spec returns false, the task is considered out of date. If they return true, Gradle does the normal behavior of checking input/output files.
It happens because folders are created during configuration phase. Add an action:
task createFolders << {
file(rootFolder).mkDirs()
}
For more details see here and here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With