Finalizer tasks run even when the finalized task is up-to-date

According to the Gradle docs,

finalizer tasks are not executed if the finalized task didn't do any work, for example if it is considered up to date

However, as per this question on StackOverflow, the following test case does not conform to the documented behavior:

task taskY << {



println 'taskY'  }

 task taskX {



outputs.upToDateWhen { true }



finalizedBy taskY



doLast { println 'taskX' }  }

When

gradle taskX

or

./gradlew taskX

are run (at least for Gradle 2.3), the following output is produced, clearly indicating that

taskX

is skipped due to being up-to-date, yet

taskY

still runs.

:taskX UP-TO-DATE  :taskY  taskY

I’ve raised GRADLE-3268 for this. I believe this is actually the intended behavior, the documentation should be updated to reflect that.