How do you use outputs.upToDateWhen in a custom task?

In a custom task you can use annotations to specify the input and output for the “up to date” check, but how do you specify an upToDateWhen closure?

If I put it in the @TaskAction method, like in the simple example below, then the task always gets executed and I get a “deprecated” message. How do you put something in the configuration phase in a custom task?

Calling TaskOutputs.upToDateWhen(Closure) after task execution has started has been deprecated and is scheduled to be removed in Gradle 2.0. Check the configuration of task ':stuff'.
class DoStuffTask extends DefaultTask {
    String message
    void doStuff() {
        outputs.upToDateWhen {
            return true
          println "${message}"

You can put such code into the constructor.

Thanks, works fine. A case of missing the obvious :slight_smile: