Subprojects lazily created are not getting configured during build

Due to legacy complex code strucure we have, i need to do this task.
My actual source code (where all java code exists) location
svnrepo/services/myrootmodule/
-----------------------------settings.gradle //i include mysub1 and mysub2 here
-----------------------------build.gradle
/**in this gradle file, i have task 'getFlatDeps' to pull out all the subprojects deps and create lib folder**/
svnrepo/services/myrootmodule/mysub1
-----------------------------build.gradle
svnrepo/services/myrootmodule/mysub2
-----------------------------build.gradle

My deployready (where we have lib,conf,bin etc) location
svnrepo/deployready/myrootservice/bin
svnrepo/deployready/myrootservice/conf
svnrepo/deployready/myrootservice/lib
svnrepo/deployready/myrootservice/
--------------------------------------------build.gradle

My job is, i need to populate the lib folder based on dependencies resolved in myrootmodule. As both svn locations are different, I DO NOT WANT TO CHECKOUT whole myrootmodule here (svnrepo/deployready/myrootservice/temp), so just checking out gradle files:
myrootservice's build.gradle

  1. First checking out rootmodule’s settings.gradle into temp folder. At this stage, i dont have subprojects checked out yet.
    svnco("svnpath,"temp/myrootmodule") //svnco my custom task
  2. Next, invoking the build of myrootmodule. Wrote another custom task:
triggerServiceBuild {
dir=temp
startParameter.projectProperties =['svcbase':'myrootmodulessvnpath']  //using this prop to checkout subprojects later
}
  1. triggerServiceBuild defined in init.script like this:
rootProject {
	
	beforeEvaluate  {
		println '***before evaluation***'
		if(project.hasProperty('svcbase') ){
				subprojects.findAll { it.getSubprojects().isEmpty() }.collect{it.path}.each {
					def subProjectPath=it.replace(':','/') //subproject names will be given with :, svn path need to be with /
					//svcbase will be set at each deploready's build.gradle file
					svnco(svcbase+subProjectPath,projectDir.path+subProjectPath)
				}
		}
}


//getFlatDependencies task present in service root level gradle files.. 
	tasks.register('triggerServiceBuild', GradleBuild){
		tasks = ['getFlatDeps'] //default tasks
		/*
		setting initscript is must to register to checkout of respective gradle files
		which avoids specifying all subprojects info again in deployready's build gradle file..
		so whenever new module added to service root's settings.gradle, this will take care of checking out that module automatically...
		*/
		startParameter.setInitScripts(gradle.getStartParameter().getInitScripts())
    }
}
  1. in myrootservice’s build.gradle ended like this:
    build.dependsOn(clean,triggerServiceBuild).finalizedBy(copyLibs) //copyLibs takes care of copying libs from temp folder’s lib to main lib folder…

When i do gradle build everyting works fine. I see subprojects getting checked out but lib is not getting populated with subprojects dependencies. Later realized, that subprojects configuration is not happening at all by the time getFlatDeps called.
But if i checkout all subprojects and root projects well before like this:


svnco("svnpath","temp/myrootmodule")  //svnco my custom task
svnco("svnpath/mysub1","temp/myrootmodule/mysub1")
svnco("svnpath/mysub2","temp/myrootmodule/mysub2") 

triggerServiceBuild {
dir=temp
startParameter.projectProperties =['svcbase':'myrootmodulesvnpath']
}

It works without any issues. I see subprojects configured in logs. In this case, i won’t even need of having beforeEvaluate closure in init.script as my code was already checked out.

But i do not want to specify all sub projects again in deployready’s build.gradle file. I want to derive the same from service root’s settings.gradle file and include them during project build. Please suggest a way to achieve this.

I know a way to write Exec task in deployready’s build.gradle to invoke gradle command (gradle -q projects) in temp folder and extract the sub projects information from output, do checkout and then call triggerServiceBuild . But is it possible to achieve like i mentioned above which make my job easer than this Exec because some projects have conditional include of subprojects and also its taking so much time (~14secs) to return the output.

can someone clarify this? how to re-configure rootproject and its subprojects once check out completed?