Load *.iml files



I am having problem importing Gradle project with subprojects into IntelliJ 2019.2. Our team builds .IML module files outside of IJ. We use iml.withXml clause to change XML properties; test source folders, etc. Additionally, we set outputFile to './idea' to collect .IML files in one place.

When pointed at ../src or build.gradle, IJ does not load generated .IML module files. Once opened, source folders are marked incorrectly, mostly everything is a source folder. For example, src/testingWidgets folder must be a test, not source.

I found a workaround

1. File-Settings->Gradle, check "Generate .IML files for modules imported from Gradle". IJ takes a few seconds to rewrite .IML files, removing our XML modifications. At this point, IJ seems to be watching IML files.
2. In Gradle tab, I execute idea task. IJ is now reading and interpreting .IML file correctly.

How can I make IJ recognize generated IML module files on opening without doing #1, #2?

PS. For legacy reason, we can't switch to recommended IJ SourceSet per Module setting yet. 

Thank you,

1 comment
Comment actions Permalink

Indeed this is not really a recommended approach to wotk with Gradle-based projects. .iml files are not supposed to be manually edited since they are re-generated by IDE on Gradle sync. ALso using idea Gradle plugin is not recommended, but instead use module per source set configuration - which makes the build experience as much close as possible to command line Gradle build.

>How can I make IJ recognize generated IML module files on opening without doing #1, #2?

For this you need to open this project not as Gradle project (not selecting the build.gradle file) but as an existing IDE project: select the directory with the .idea project configuration sub-folder. This way IDE will not use Gradle import workflow when opening project and will not overwrite but will re-use existing configuration.


Please sign in to leave a comment.