Thunderforge
Thunderforge

Reputation: 20595

Is there a way to add a custom up to date condition while preserving the original one?

Say that I am using a Gradle plugin that defines task foo, which is up to date under a certain condition. Unfortunately, I don't have the source, so I don't know when it is.

I would like to make it so that foo is up to date if the original condition is true, and if a custom condition is also true.

I know I can add my custom condition like this:

foo.outputs.upToDateWhen {
    return myCondition == true
}

But I want to be able to do something like this:

foo.outputs.upToDateWhen {
    return super.upToDateWhen && myCondition == true
}

Is there any way to do what I am looking for? Can I add an up to date condition in such a way that I can have it preserve the original up to date condition?

Upvotes: 0

Views: 524

Answers (1)

Lukas Körfer
Lukas Körfer

Reputation: 14543

What you describe is actually the default behaviour. The description of the upToDateWhen method in the docs is:

Adds a predicate to determine whether the outputs of this task are up-to-date. The given closure is executed at task execution time. The closure is passed the task as a parameter. If the closure returns false, the task outputs are considered out-of-date and the task will be executed.

You can add multiple such predicates. The task outputs are considered out-of-date when any predicate returns false.

Upvotes: 1

Related Questions