I am working with the following project structure Project
---Subproject1
---Subproject2
---Subproject3
|build.gradle
|settings.gradle
Subproject2 depends on Subproject 1
Subproject3 depends on Subproject 2
For all subprojects I need to have task "build", which will be custom for each project. But some initialization task (same for all subprojects) must be executed before "build". Thing is - this initialization task must be executed once and only once during build, no mater what I'm building - root project or any of subprojects. For example, if I do build of Subproejct3, sequence must be following: init build Subproject1 build Subproject2 build Subproject3
I tried to define "doFirst" for "build" at root project build.gradle and put "init" code into it. But in this case "init" code executed before each "build". I tried to define dependency on root for each "build" but faced same problem as previously.
This is quite simple with Gradle. Define your init
task (probably in root project) and customize build
tasks in your subprojects to depend on this init like
build.dependsOn ':init'
More details at http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html
BTW: every tasks can be executed only once when a build is started so it seems that you have added your task action using doFirst() multiple times or added it to multiple tasks that were executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With