outputs.upToDateWhen confusion

I have a custom task class, similar to the following:

class CustomTask extends DefaultTask {

  @OutputFile
  File file
  @OutputDirectory
  File dir

  @TaskAction
  def taskAction() {
    // run some application code to work with file and dir
}

Then I configure the task:

project.task(taskName, type: CustomTask) {
  file fileVar
  dir dirVar

  // I always want it to run
 // I need to tweak the application code before enabling incremental support
  outputs.upToDateWhen { true }

}

I will eventually enable full incremental build support, but the application code needs a few tweaks first. So for now, I just want to turn off the incremental support. But… I want to take advantage of automatically creating directories, so I don’t want to remove the @OutputFile and @OutputDirectory. Thus, I put in the upToDateWhen code for this reason. But… I still get the task being up to date when “file” and “dir” haven’t changed.

Is this is desired behavior? If so… then I’m not sure what the upToDateWhen is for.

FYI… for now, I’ve removed all the @Output annotations, and just done an old-fashioned Groovy file.mkdirs() and dir.mkdirs(). But I would like to understand upToDateWhen better.

If you read “false” as “not”, then…

outputs.upToDateWhen { true } means “outputs are up to date”.

outputs.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 Like

facepalm

Thanks Sterling.