# Behavior when depending on assemble life-cycle task

**URL:** <https://discuss.gradle.org/t/behavior-when-depending-on-assemble-life-cycle-task/42681>\
**Category:** Help/Discuss\
**Created:** [April 13, 2022, 2:03pm UTC](https://discuss.gradle.org/t/behavior-when-depending-on-assemble-life-cycle-task/42681 "2022-04-13T14:03:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricSalemi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ericsalemi/32/9734_2.png) [@EricSalemi](https://discuss.gradle.org/u/EricSalemi)\
**Post date:** [April 13, 2022, 2:03pm UTC](https://discuss.gradle.org/t/behavior-when-depending-on-assemble-life-cycle-task/42681/1 "2022-04-13T14:03:18Z")

</div>

I’m puzzled by the behavior of the assemble life-cycle task.  
Below a minimal example.

Root `build.gradle` file is:

```gradle
plugins {
    id 'base'
}

task task1 {
    doLast {
        println 'Task #1'
    }
}

task task2 {
    dependsOn assemble
    doLast {
        println 'Task #2'
    }
}

assemble.dependsOn(task1)

```

Sub-project `a/build.gradle` file is:

```gradle
plugins {
    id 'base'
}

task task3 {
    doLast {
        println 'Task #3'
    }
}

assemble.dependsOn(task3)

```

`settings.gradle` file is:

```gradle
include 'a'

```

Executing `assemble` task:

```gradle
> gradle assemble

> Task :task1
Task #1

> Task :a:task3
Task #3

```

Executing `task2` gives:

```gradle
> gradle task2   

> Task :task1
Task #1

> Task :task2
Task #2

```

Why is `task3` executed when executing `assemble` task directly but not when executing `task2`? I was assuming that `assemble` is special in the sense that it depends on all sub-projects `assemble` tasks but it does not seem to hold when a task depends on `assemble`. I must be doing something wrong but I can’t figure out what…

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [April 13, 2022, 3:24pm UTC](https://discuss.gradle.org/t/behavior-when-depending-on-assemble-life-cycle-task/42681/2 "2022-04-13T15:24:37Z")

</div>

> [@EricSalemi](#):
>
> I was assuming that `assemble` is special in the sense that it depends on all sub-projects `assemble` tasks but it does not seem to hold when a task depends on `assemble` .

There is no dependency relationship between the `:assemble` and `:a:assemble` tasks. They are independent tasks. Running `gradle assemble` is not the same as running `gradle :assemble`.

When you run `gradle assemble`, you are asking Gradle to run the `assemble` task in every project in the build, not just the root project `:assemble` task. The `:a:assemble` task is running because you’re asking for it to run, not because of a task dependency.

More Info:  
[https://docs.gradle.org/current/userguide/command\_line\_interface.html#sec:command\_line\_executing\_tasks](https://docs.gradle.org/current/userguide/command_line_interface.html#sec:command_line_executing_tasks)
