How create build.gradle that execute other build.gradle files in subfolders

Hello.
I’m novice in Gradle. There are a lot subfolders with build.gradle files. How can I create build.gradle file in root folder that execute build.gradle files in subfolders ?

Hi Alex,

most likely you deal with a multiproject project here. A multiproject build is one build that builds multiple project at once. checkout the gradle userguide section about multiproject builds at https://docs.gradle.org/current/userguide/multi_project_builds.html to learn more on how to deal with them.

hope that helps,

cheers,
rené

Thank Rene.
We are using multi_project build in the case when we know:
include XX
include YY

In the case when subprojects are added and deleted dynamic?

I found some code:
def flist =
new File(‘.’).eachDir {
if (it.name!=‘.gradle’) {
flist << it.name
}
}

flist.each { folder →
task “${folder}”(type: GradleBuild) {
buildFile = folder + “/build.gradle”
dir = ‘./’ + folder
tasks = [‘build’]
}
}

task all(dependsOn: flist) {
}

but I got a error:
A problem occurred evaluating root project ‘workspace’.

Cannot add task ‘:build’ as a task with that name already exists.
Is it possible automate this task?

It doesn’t require any special file system navigation. Just keep in mind that if you are in the context of a project, you will either use the build.gradle in the project’s folder or gradle will go up the file hierarchy till it finds one.

So from the top level build.gradle if you fire a task in a subproject (e.g. “:subproject:mySubprojectTask”), that will switch you to the context of the subproject. If there’s a build.gradle in the subproject folder, it will look for the task there.

Thank you very much.