Difference between calling a task and dependsOn a task


(Serhii) #1

Why if i call build task on root project, then it is called in all subprojects too.
But if i specify dependsOn build in root project for some other task and call that task, then build is not called in subprojects.

For example

task publish {
    dependsOn build
}

When publish is called, build is not called in subprojects.

What is the logic behind this?


(Sterling Greene) #2

It’s because the command-line tries to be helpful and searches for tasks in all subprojects.

task publish {
    dependsOn build
}

Means publish depends on the task named build. Gradle doesn’t look for any other task named build.

gradle build means "run all tasks that match the name build"
gradle :build means "run the task with the path :build"
gradle :subproject:build means "run the task with the path :subproject:build"