# outputs.upToDateWhen confusion

**URL:** <https://discuss.gradle.org/t/outputs-uptodatewhen-confusion/17973>\
**Category:** Help/Discuss\
**Created:** [June 8, 2016, 6:56pm UTC](https://discuss.gradle.org/t/outputs-uptodatewhen-confusion/17973 "2016-06-08T18:56:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stewartbryson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stewartbryson/32/9981_2.png) [@stewartbryson](https://discuss.gradle.org/u/stewartbryson)\
**Post date:** [June 8, 2016, 6:56pm UTC](https://discuss.gradle.org/t/outputs-uptodatewhen-confusion/17973/1 "2016-06-08T18:56:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stewartbryson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stewartbryson/32/9981_2.png) [@stewartbryson](https://discuss.gradle.org/u/stewartbryson)\
**Post date:** [June 8, 2016, 7:06pm UTC](https://discuss.gradle.org/t/outputs-uptodatewhen-confusion/17973/2 "2016-06-08T19:06:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [June 8, 2016, 7:50pm UTC](https://discuss.gradle.org/t/outputs-uptodatewhen-confusion/17973/3 "2016-06-08T19:50:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stewartbryson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stewartbryson/32/9981_2.png) [@stewartbryson](https://discuss.gradle.org/u/stewartbryson)\
**Post date:** [June 9, 2016, 2:36am UTC](https://discuss.gradle.org/t/outputs-uptodatewhen-confusion/17973/4 "2016-06-09T02:36:57Z")

</div>

_facepalm_

Thanks Sterling.
