Task up-to-date but OutputFile not created

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?

You could use TaskOutputs.upToDateWhen(Closure c)

eg:

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