Partial Intellij idea project files generation

What is the most efficient way to generate intellij idea files partially in gradle, while honoring java dependencies?
with monolithic repositories, gradlew idea might consume a lot of time & memory for both the idea task execution and the project load in the IDE itself. I want to run just root’s ideaProject, ideaWorkspace, and some sub-projects’ ideaModule that I wish to load
e.g. if I want to load project A while it depends on project B in the compile / testCompile configuration, I want to make :A:idea depend on :B:idea
How can it be done?