In a multi-project Android build, like
root
+--- build.gradle
+--- settings.gradle
+--- subproject1
\--- build.gradle
\--- subproject2
\--- build.gradle
I would like to execute a task that generates code, before any of the projects (subproject1
,subproject2
) build. The code generating task is there once for all projects. I would like to put it into the root build.gradle
. Also in the root build.gradle
, that all projects (allprojects
) depend on the code generating task.
task code_generating_task << {
println "I generate code here"
}
preBuild.dependsOn code_generating_task
Does not work, because preBuild is not defined in the root build.gradle
.
It is fine to declare a common/transverse task directly in the root project's build script like you did. In order to create dependencies between each subproject's preBuild
task and this common code_generating_task
task you can write the following block in the root project build script:
gradle.projectsEvaluated {
subprojects{
// TODO : add a check on 'preBuild' task existence in this subproject.
preBuild.dependsOn code_generating_task
}
}
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