# Task Ordering Problem - mustRunAfter finalizer dependencies

**URL:** <https://discuss.gradle.org/t/task-ordering-problem-mustrunafter-finalizer-dependencies/14035>\
**Category:** Bugs\
**Tags:** gradle-3389, issue-acknowledged\
**Created:** [January 29, 2016, 1:53pm UTC](https://discuss.gradle.org/t/task-ordering-problem-mustrunafter-finalizer-dependencies/14035 "2016-01-29T13:53:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rLonsdale](https://avatars.discourse-cdn.com/v4/letter/r/2acd7d/32.png) [@rLonsdale](https://discuss.gradle.org/u/rLonsdale)\
**Post date:** [January 29, 2016, 1:53pm UTC](https://discuss.gradle.org/t/task-ordering-problem-mustrunafter-finalizer-dependencies/14035/1 "2016-01-29T13:53:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gary\_Hale](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gary_hale/32/7647_2.png) [@Gary\_Hale](https://discuss.gradle.org/u/Gary_Hale)\
**Post date:** [February 1, 2016, 4:52pm UTC](https://discuss.gradle.org/t/task-ordering-problem-mustrunafter-finalizer-dependencies/14035/2 "2016-02-01T16:52:49Z")

</div>

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