Order of elements in IML files
Answered
Hi,
I'm working on IML file generation for the Mill build system and I'd like to confirm an assumption I made with some help from GitHub Copilot when searching the open source IntelliJ platform repositories.
Is the order of elements (particularly components) in IML files stable? Does IDEA sort the components lexicographically by name? That seems to match the behaviour I'm seeing but I'd love to know whether this is guaranteed.
Regards,
Ondřej
Please sign in to leave a comment.
Confirmed — IDEA serializes `.iml` components alphabetically by name, via a `TreeMap<String, Element>` in [ProjectStoreBridge.kt](https://github.com/JetBrains/intellij-community/blob/master/platform/configuration-store-impl/src/ProjectStoreBridge.kt).
That's current behavior, not a documented format contract. The loader is name-keyed, so files in any order load correctly — order only affects diff stability. Matching the alphabetical ordering will minimize diffs against IDEA-rewritten files.
Inner elements (content roots, source roots) have their own intentional ordering — see [roots_extensions.kt](https://github.com/JetBrains/intellij-community/blob/master/platform/workspace/jps/src/com/intellij/platform/workspace/jps/entities/roots_extensions.kt) ("to avoid unnecessary modifications of iml file").