How to keep project specific iml files out of a GIT repository.

I like using IntelliJ IDEA from JetBrains as the IDE for developing Erlang.

There’s just one small problem. It automatically creates a file in the module directory with the file extension iml to store module-specific information. However, you don’t really want this file in the next Git commit, as it is only relevant for developers who also work with IntelliJ IDEA.

One way to prevent this would be to adjust the file .gitignore accordingly. But this is not a very elegant solution because otherwise .gitignore is quickly overloaded with restrictions that are only relevant for a specific IDE.

So here’s my tip for getting round this in a more elegant way.

I move the iml file to the project directory and then change the file modules.xml in the directory .idea for the parameters fileurl and filepath accordingly.

For those of you wanting a bit more meat on the bone here’s the steps in detail for the example project my_project and the example module my_modul:

  1. End IntelliJ IDEA.
  2. Move the file my_project/my_module/xxx.iml to the directory my_project.
  3. Open the file .idea/modules.xml with an editor.
  4. Change fileurl="file://$PROJECT_DIR$/my_module/my_module.iml" to fileurl="file://$PROJECT_DIR$/my_module.iml".
  5. Change filepath="$PROJECT_DIR$/my_module/my_module.iml" to filepath="$PROJECT_DIR$/my_module/my_module.iml" .
  6. Write the changes back to the modules.xml file.
  7. Start IntelliJ IDEA again.

This might look a bit complicated, but in fact it’s really quite easy and helps avoid any unwanted clutter in the Git repository.