Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task is always up to date

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?

like image 606
Steve Mitcham Avatar asked Mar 13 '15 17:03

Steve Mitcham


People also ask

Why gradle task is up to date?

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.

What is up to date in gradle?

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.

Is not up to date because task upToDateWhen is false?

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.


1 Answers

It happens because folders are created during configuration phase. Add an action:

task createFolders << {
  file(rootFolder).mkDirs()
}

For more details see here and here.

like image 93
Opal Avatar answered Dec 09 '22 18:12

Opal