# Controlling task configuration order

**URL:** <https://discuss.gradle.org/t/controlling-task-configuration-order/33948>\
**Category:** Help/Discuss\
**Created:** [November 19, 2019, 11:07pm UTC](https://discuss.gradle.org/t/controlling-task-configuration-order/33948 "2019-11-19T23:07:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hnine999](https://avatars.discourse-cdn.com/v4/letter/h/bc8723/32.png) [@hnine999](https://discuss.gradle.org/u/hnine999)\
**Post date:** [November 19, 2019, 11:07pm UTC](https://discuss.gradle.org/t/controlling-task-configuration-order/33948/1 "2019-11-19T23:07:34Z")

</div>

Hello.

I have a gradle build script where:

- Task B dependsOn Task A
- IThe configuration of Task B depends on extensions made in the configuration of Task A

tasks.register(“TaskA”) {  
ext[“TaskAExt”] = SomeImportantObject  
}

tasks.register(“TaskB”) {  
dependsOn(“TaskA”)  
val someImportantObject = ext[“TaskAExt”]  
}

Unfortunately, it appears that, even though TaskB is _executed_ after TaskA, TaskB is _configured_ **before** TaskA. This causes the configuration of TaskB to error out with the message:

Cannot get property ‘TaskAExt’ on extra properties extension as it does not exist.

Is there any way to control the order of the configuration of the tasks, in particular so that TaskA is configured before TaskB?

---

<div class="post-metadata">

**Author:** ![shadowface](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/shadowface/32/8552_2.png) [@shadowface](https://discuss.gradle.org/u/shadowface)\
**Post date:** [May 31, 2020, 3:21pm UTC](https://discuss.gradle.org/t/controlling-task-configuration-order/33948/2 "2020-05-31T15:21:57Z")

</div>

try to register `task B` on the last steps of `task A` and like you did make `B` depend on `A`

```gradle
tasks.register(“TaskA”) {
    ext[“TaskAExt”] = SomeImportantObject
    doLast {
        tasks.register(“TaskB”) {
        dependsOn(“TaskA”)
        val someImportantObject = ext[“TaskAExt”]
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [June 1, 2020, 5:39am UTC](https://discuss.gradle.org/t/controlling-task-configuration-order/33948/3 "2020-06-01T05:39:56Z")

</div>

> [@shadowface](#):
>
> try to register `task B` on the last steps of `task A`

Don’t do this. Gradle has a “configuration” phase and an “execution” phase. A doLast {…} closure is running in the “execution” phase and by this time gradle has calculated the [TaskGraph](https://docs.gradle.org/current/javadoc/org/gradle/api/execution/TaskExecutionGraph.html) so it’s too late to be adding tasks to the model

See [build phases](https://docs.gradle.org/current/userguide/build_lifecycle.html#sec:build_phases)
