If I have two tasks: `taskB` depends on `taskA`, b...
# community-support
a
If I have two tasks:
taskB
depends on
taskA
, but
taskB
is disabled. When I run
gradle taskB
, why does Gradle still run
taskA
? Shouldn't it also be skipped?
Copy code
val taskA by tasks.registering {
  doLast {
    println("running $path")
  }
}

val taskB by tasks.registering {
  enabled = false
  onlyIf { false }
  dependsOn(taskA)
  doLast {
    println("running $path")
  }
}
Copy code
./gradlew taskB
> Task :taskA
running :taskA
> Task :taskB SKIPPED
BUILD SUCCESSFUL in 175ms
v
No, that's expected. If you exclude a task, the dependencies are also excluded (if not included by something else). But setting
enabled
to
false
is just skipping the work of that task and does not influence dependency tasks.
It is like doing
onlyIf { false }
Which is only calculated right before the task is executed to for example react on things other tasks did and thus could not even be evaluated before the dependency tasks already were run.
You could fake the
-x
by adding the task path to the
StartParameters
setting, that would then work like using
-x
and thus also exclude the dependency tasks.
This can still be done in the configuration phase
x
4
⁉️ 1
v
?