有没有办法在保留原始条件的同时添加自定义最新条件?

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

假设我正在使用定义任务 foo 的 Gradle 插件,它在特定条件下是最新的。不幸的是,我没有来源,所以我不知道它是什么时候。

如果原始条件为真,并且自定义条件也为真,我想做到 foo 是最新的。

我知道我可以像这样添加自定义条件:

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

但我希望能够做这样的事情:

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

有什么方法可以满足我的需求吗?我可以添加一个最新条件以使其保留原始的最新条件吗?

您所描述的实际上是默认行为。 the docsupToDateWhen方法的描述是:

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.