How do I create an IDEA project from a complex gradle project?

We have a very complex gradle project, with over 400 modules, each controlled by a build.gradle file three directory levels down from the main project and #included. Running the idea plugin generates a mess, with many projects getting two .iml files: one in the project directory, and one in a newly created directory three levels down. For example, given a main directory “mod” and a subproject at “mod/store/file/store” the plugin creates both:

mod/store/file/store/store/file/store.iml, and mod/store/file/store/store_file_store.iml

as well as placing the path mod/store/file/store/src/main/java in the source paths in mod/mod.iml

How do I fix this?

This is not a proper behavior but I cannot say what is wrong here. Can you make a simple example showing how you set up your projects where we can see actual snippets from your Gradle files?