Finalizer tasks that depend on the base task do not execute if the base task fails

(Carsten Mjartan) #1

I have two tasks A and B where A is finalized by B and B depends on A:

task A {
  finalizedBy "B"
 doLast {
  println 'A'
  throw new RuntimeException()
   task B(dependsOn:A) << {
 println 'B'

If any of the tasks is executed, A fails (as expected), but B doesn’t get executed. In my opinion it would be better to respect the finalizedBy relation for these cases and always execute B.

finalizedBy and failures of dependent tasks
(Luke Daley) #2

What’s the use case here? Why would you want to depend on a task and be finalized by it?

Tasks can only ever run once in a build, so this situation can’t be satisfied.

(Perryn Fowler) #3

Hi Carsten,

Could you explain why you want to set up tasks like that? I have recreated your problem, but I am interested in why you want a task to depend on something that it finalises?

cheers Perryn

(Carsten Mjartan) #4

In my example I don’t depend on the finalizer task, but the finalizer task depends on the base task. My current use case is a report that is generated also on test failure. It should also run the tests if the report itself is requested.

(Carsten Mjartan) #5

Maybe the semantics of finalizedBy is not really clear (to me). I expected that finalizedBy calls B after executing A, but also tells Gradle that B does not depend on the success of A at all.

(Perryn Fowler) #6

Hi Carsten,

You have the semantics of finalizedBy correct, but it will not work that way if you ALSO have B depend on A. We are considering what we can do about that.

For now, I’d suggest that you have A finalized by B but not have B dependOn A. For your use case this will mean that the reports will always be generated when you run the tests, but that you can’t trigger the tests by requesting the reports. This is similar to how testing and reports work in the java plugin.


(Luke Daley) #7

Raising this on the dev list for discussion.