How to make a custom task depend on the root "build" task?

(David) #1

I want to have a custom task that depends on the root “build” task… so I tried this:

task MyTask(dependsOn: ‘:build’) {
doLast {
println “My task”

But all I get is an error with “Task with path ‘:build’ not found in root project”

Using “gradle tasks” definitely shows a “build” task in the root project…

(David) #2

Found the answer here:

Since my root project does not declare any plugins (all my java modules are in subprojects), then I don’t have the “build” task in the root project. It turns out the “build” task is only added by the “java-base” plugin, and that is automatically included by the “java” plugin.

The default output of “gradle tasks” makes it look like the “build” task is available on the project, hence the confusion.

Changing the task definition to: dependsOn(’:subproject:build’) works as expected.