# Task up-to-date but OutputFile not created

**URL:** <https://discuss.gradle.org/t/task-up-to-date-but-outputfile-not-created/17568>\
**Category:** Help/Discuss\
**Created:** [May 12, 2016, 1:15pm UTC](https://discuss.gradle.org/t/task-up-to-date-but-outputfile-not-created/17568 "2016-05-12T13:15:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_d\_Anjou](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/martin_d_anjou/32/5248_2.png) [@Martin\_d\_Anjou](https://discuss.gradle.org/u/Martin_d_Anjou)\
**Post date:** [May 12, 2016, 1:15pm UTC](https://discuss.gradle.org/t/task-up-to-date-but-outputfile-not-created/17568/1 "2016-05-12T13:15:17Z")

</div>

Here is a task that declares one input file and one output file. I expect Gradle to execute the task action as long as the output file does not exist, but Gradle says the task is up-to-date, without checking whether the output file exists or not.

```
class MyProcess extends DefaultTask {
    @InputFile
    File inputFile

    @OutputFile
    File outputFile

    @TaskAction
    void perform() {
        // Oops, the user forgot to effectively create the output file
    }
}

task perform(type: MyProcess) {
    inputFile file('build.gradle')
    outputFile file("${buildDir}/file1.bin")
}

```

First run:

```
$ gradle perform
:perform

```

Do it again, the output file does not exist:

```
$ gradle perform
:perform UP-TO-DATE

```

What do I need to do to the `MyProcess` class to get Gradle to run the task action when the output file doesn’t exist?

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [May 12, 2016, 2:44pm UTC](https://discuss.gradle.org/t/task-up-to-date-but-outputfile-not-created/17568/2 "2016-05-12T14:44:08Z")

</div>

You could use [TaskOutputs.upToDateWhen(Closure c)](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskOutputs.html#upToDateWhen(groovy.lang.Closure))

eg:

```gradle
class MyProcess extends DefaultTask {
   MyProcess() {
      outputs.upToDateWhen {
         outputFile.exists()
      } 
   } 
   // etc
} 

```
