Introduction
An .iml file describes a module in JetBrains’
IntelliJ IDEA and the other IDEs built on
the same platform, such as PyCharm and Android Studio. A project is made of one or more
modules; each module’s file lists its source, test and resource folders, the folders to
leave out, and the libraries and other modules it depends on.
The project’s own settings live in the .idea folder beside it, as a set
of XML files, including modules.xml, which lists the project’s
.iml files. When a project is imported from Maven or
Gradle, the IDE works the modules out from the build
files instead, and may not write .iml files at all.
Structure
An .iml file is XML with a module root whose
type attribute names the kind of module, such as
JAVA_MODULE. A component element named
NewModuleRootManager holds a content element with the
sourceFolder and excludeFolder entries, then
orderEntry elements for the SDK, the module’s own sources, libraries and
other modules. Paths are written relative to the module with the
$MODULE_DIR$ macro.
Inside content, a sourceFolder is marked as tests with
isTestSource="true", and resource folders carry a type such
as java-resource. The orderEntry elements are read in order
and their type says what each one is: inheritedJdk or
jdk (a jdkName is given) for the SDK,
sourceFolder for the module’s own sources, library (with
name and level), module (with
module-name) or module-library. Any of them can give a
scope, such as TEST or PROVIDED, and
exported. A dropped .iml file opens in the explorer, with
its source folders and dependencies listed.
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Not described
Known, not yet covered
- Viewer: only the module root manager component gets an Overview (module type, content roots, source folders, dependencies). Other components, such as facets, appear only in the XML tree and the text.
- Reference: the component names other than
NewModuleRootManagerare not listed here.
Links
Software
- IntelliJ IDEA – JetBrains’ Java and Kotlin IDE, which writes module files (Windows, macOS, Linux)
- PyCharm – JetBrains’ Python IDE; the other JetBrains IDEs use the same files (Windows, macOS, Linux)
- Android Studio – Google’s Android IDE, built on IntelliJ IDEA (Windows, macOS, Linux)