Task that dynamically depends on subproject's task


I want to create a task let’s say “rootTask”, that dynamically according to some computation, depends on all tasks of type “Test” from some of the subprojects.

The problem is, that if this computation runs in the “doFirst” of the rootTask, then the taskGraph is already finalized. If i’m doing it in the configuration phase, then the subprojects’ tasks are not created yet.

Also, i’d prefer (though not a must) that the computation will only run if “rootTask” is being called.

What’s the best approach of doing this?