0

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?

Thunderforge
  • 19,637
  • 18
  • 83
  • 130

1 Answers1

1

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.

Community
  • 1
  • 1
Lukas Körfer
  • 13,515
  • 7
  • 46
  • 62