How to rewrite a task which list projects and checks their loaded plugins in order to comply with configuration cache

Hi,

I have this task which i need in my ci build. I analyze the modules based on this and then make decisions which tasks to run. I tried to use the configuration cache but it fails for me. Is there a way to make this eligible for configuration cache? I use here many gradle objects like plugins so i have no idea how to start with this.

tasks.register("listProjects") {
    doLast {
        val projectModules = subprojects.map {
            mapOf(
                    "name" to it.path,
                    "buildFile" to it.buildFile.path,
                    "isAssetModule" to it.plugins.hasPlugin("com.android.asset-pack"),
                    "isApplicationModule" to it.plugins.hasPlugin("com.android.application"),
                    "isLibraryModule" to it.plugins.hasPlugin("com.android.library"),
            )
        }
        print(groovy.json.JsonOutput.toJson(projectModules))
    }
}