Task Ordering Problem - mustRunAfter finalizer dependencies

Hi,

I have one task (let’s call it “B”) that is finalized by another (called “C”), but which also “must run after” a third (“A”). However, “C” also depends on “A”, so calling “gradle B” invokes all three tasks to run as follows:

B --> is finalized by --> C --> which depends on --> A

However, due to the “must run after” relationship between B and A, I would expect A to execute first, but it doesn’t.

Here is a sample build.gradle to reproduce the problem:

task A

task B {
	mustRunAfter "A"
	finalizedBy "C"
}

task C {
	dependsOn "A"
}

Here is the result I would expect when calling “gradle B”:

:A UP-TO-DATE
:B UP-TO-DATE
:C UP-TO-DATE

But, I actually get:

:B UP-TO-DATE
:A UP-TO-DATE
:C UP-TO-DATE

with B executing before A, even through B “must run after” A. If I run “gradle B A” instead, the tasks execute in the correct order - it seems to occur only when A’s execution is invoked by a “finalizer” dependency. Interestingly, the task graph as printed with the --info flag shows the tasks in the correct order, but they are then executed differently.

I believe this is a bug, unless I’ve misunderstood the documentation. I’m using gradle 2.10.

Thanks
Rowan

I’ve confirmed the behavior and opened https://issues.gradle.org/browse/GRADLE-3389 to track the issue.