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

(calimero7) #1

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}"

(Peter Niederwieser) #2

You can put such code into the constructor.

(calimero7) #3

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