Does root in multiproject needs to be configured?

In my multiproject setup like below

RootProject
  -buildSrc
  -DirectoryA
     -SubProjectA1
     -SubProjectA2
     -SubProjectA3
  -DirectoryB
     -SubProjectB1
     -SubProjectB2
  -DirectoryC
     -SubProjectC1
     -SubProjectC2

I have a task that is created on the root level (In RootProject-> build.gradle). Because I want this task to be invoked from the root level like this

gradle myTask

But if I only configure subprojects like below

configure(mySubprojects()) { 
   ...
   dependencies { ... } 
   repositories {...} 
}

Then in myTask configurations.runtime does not contain external dependencies.

Even though I iterate through every subproject and grab these dependencies.

task myTask(type: JavaExec) {
    ...
    mySubProjects().each{ classpath = classpath.plus(it.configurations.runtime) }
   ...
}

However if I also configure the root project in the root build.gradle as below, the problem goes away and all dependencies are included.

configure(project) { 
   ...
   dependencies { ... } 
   repositories {...} 
}

Could someone please point me in some direction? I’m probably missing something here. But I really wouldn’t want to configure that root project just for the sake of having dependencies included in my subprojects. I was hoping they are already there since I configure them with configure(mySubProjects())

mySubprojects btw is just a collection of subprojects, had to use it to avoid gradle adding empty directories.

Thanks!

Use allprojects instead of subprojects.

Thanks Schalk but allprojects would configure all non-project directories as subprojects (DirectoryA, DirectoryB etc…) including RootProject. Something I wanted to avoid in the first place. Or am I misunderstanding you?

@johny123, the way I understood your question is that you wanted to apply that to both the root project and all of the subprojects. Effectively allprojects is just equivalent of subprojects + rootProject. The projects in subprojects are populated via include statements in settings.gradle. So allprojects cannot configure non-project directories.

Can you post what your settings.gradle file and your subProjects() method looks like? I might be completely misunderstanding what you are trying to set up.