Regarding multi project build

I have the below project structure

myprojects ( root folder )
    component1
 settings.gradle
  projectP1 ( have their own build.gradle)
  projectP2 ( have their own build.gradle)
    component2
 settings.gradle
  projectP3 ( have their own build.gradle)
  projectP4 ( have their own build.gradle)

Component1 and Component2 are two multiprojects with a settings.gradle. Since gradle does not support nested settings.gradle , in order to build my components from the “myprojects” folder , I have .bat file in the “myprojects” folder

I would like to get rid of the .bat/.sh file to run the build from “myprojects” folder. I am planning to have

a build.gradle under “myproject” folder which will have a task. The task will recursively loop through the individual multiprojects and invoke gradle build.

Before proceeding , I would like to know whether my approach is feasible.

In case if there are any samples to read directories in groovy , please provide.

I tried the below build

String[] components = ["component1","component2"]
  task buildAllComponents(type: GradleBuild) {
    components.each(){
     println
" Building
${it} "
     buildFile ="${it}/build.gradle"
     tasks << 'build'
           }
      }

Only the last component in the list of components is getting build. can you let me know the error in logic ?

Found a solution.

String[] buildOrder = ["component1","component2"]
  task buildAllComponents() {
      buildOrder.each { def componentName ->
      tasks.add(name: "build$componentName", type: GradleBuild) {
   buildFile = componentName + "/build.gradle"
  tasks = ['clean','build','upload']
           }
  }
    buildOrder.each{
  println " ******** BUILDING ******** " + it
   String taskName = "build" + it
   tasks."$taskName".execute()
 }
      }