[Android] How to pass runtimeConfiguration.resolvedConfiguration.firstLevelModuleDependencies to a task?

I am an Android developer, and I am currently developing a plugin that needs to know which modules are involved in this compilation, such as building an APK.

Here’s what I’ve done.
Assemble routers of all modules involved in this compilation and have specific dependence.

Since Task is not allowed to reference Configuration when configuration-cache is on, so I need to get the firstLevelModuleDependencies and convert it to a cacheable object before task created.

The problem is, obtain firstLevelModuleDependencies too early will cause gradle configuration fail.

I’m thinking of getting the firstLevelModuleDependencies from the output of another task, but I don’t know how.

OK,I solved it with runtimeConfiguration.incoming.afterResolve{}

variant.runtimeConfiguration.incoming.afterResolve {
    // do whatever you want with variant.runtimeConfiguration.resolvedConfiguration.firstLevelModuleDependencies
    // then pass it to task