lukasz-karolewski
lukasz-karolewski

Reputation: 379

gradle 'build' task confusion

Hi I have multi project gradle setup

-root_project
|-sub_project1
|-sub_project2
|-sub_project3

All works great 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 call from command line 'gradlew' <- default task gets executed

when i call from command line 'gradlew tasks' <- task under 'all task runnable from root project' i see 'build'

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

What went wrong: Execution failed for task ':tasks'.

Could not determine the dependencies of task ':buildroom'.

'base' plugin adds 'assemble', and 'clean' task but not build...

any tips?

Upvotes: 10

Views: 21344

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

The build task is declared by the java-base plugin. It's likely that your root project doesn't (directly or indirectly) apply java-base and therefore doesn't have a build task. This is why dependsOn("build"), which adds a task dependency on a task named build in the same project, eventually causes an error. defaultTasks is different in that:

  • It only accepts task names (whereas dependsOn also accepts task paths and Task objects).
  • Its task names get resolved to tasks as if the task names had been entered on the command line. In other words, all projects are searched for a task with the given name, and the set of matching tasks is returned.

Upvotes: 13

Related Questions