Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle 'build' task confusion

Tags:

gradle

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?

like image 401
lukasz-karolewski Avatar asked Mar 20 '13 21:03

lukasz-karolewski


People also ask

What is afterEvaluate in Gradle?

> gradle -q test Adding test task to project ':project-a' Running tests for project ':project-a' This example uses method Project. afterEvaluate() to add a closure which is executed after the project is evaluated. It is also possible to receive notifications when any project is evaluated.

What is doLast in Gradle task?

doFirst(action) Adds the given Action to the beginning of this task's action list. doLast(action) Adds the given closure to the end of this task's action list. The closure is passed this task as a parameter when executed.

What is buildSrc in Gradle?

buildSrc is a directory at the Gradle project root, which can contain our build logic. This allows us to use the Kotlin DSL to write our custom build code with very little configuration and share this logic across the whole project.


1 Answers

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.
like image 62
Peter Niederwieser Avatar answered Sep 28 '22 12:09

Peter Niederwieser