Gradle "build" task confusion

Hi, I have some gradle setup projects

-root_project |-sub_project1 |-sub_project2 |-sub_project3 

Everything works fine, but one thing drives me crazy. In my build script:

 defaultTasks 'build' <- this works just fine task buildroom (description: 'This task is invoked by build room script, invokes default task plus publishes artifacts') { // dependsOn('build') <-- this doesn't work // alternative dependsOn(":sub_project1:build") dependsOn(":sub_project2:build") 

when I invoke 'gradlew' <from the command line - the default task is executed

when I call from the command line 'tasks gradlew' <- task under 'all tasks launched from the root project' I see 'build'

but when I try to add dependOn ('build'), dependOn (': build') or dependsOn (': root: build'), it tells me

What went wrong: Completed for the Tasks task.

Could not determine task dependencies: buildroom.

The "base" plugin adds a "build" and a "clean" task, but does not build ...

any advice?

+7
source share
1 answer

The build task is declared by the java-base plugin. Your root project probably does not (directly or indirectly) use java-base and therefore does not have a build task. This is why dependsOn("build") , which adds a task dependency to a task named build in the same project, ultimately causes an error. defaultTasks differs in that:

  • It accepts task names (whereas dependsOn also accepts task paths and Task objects).
  • The names of his tasks are solved for tasks as if the names of tasks were entered on the command line. In other words, all projects are looking for a task with the given name, and a set of corresponding tasks is returned.
+10
source

All Articles