Search code examples
intellij-idea

Why does IntellijIDEA delete root iml module after renaming of root directory? How to correctly rename directory with Maven project?


IntellijIDEA Ultimate 2020.1 version.

  1. Created File/New Project/Maven/MyMavenJava
  2. Created one class, one test, set up pom.xml, all is compiled, all is ok. So I have a one project with a one IntellijIDEA module on the root of a project. Project Structure/Modules/ has MyMavenJava.
  3. Copied a MyMavenJava into Desktop and renamed a MyMavenJava directory into NewName and opened.
  4. .iml file was deleted, .java files had received icon with 'j' in orange circle, Structure/Modules/ has MyMavenJava and NewName.

p.s. The most strange thing is that when a MyMavenJava is renamed into MyMavenJava123 - all this troubles don't even occur! I tried different way to identify all this steps and this poisons my understanding of project's configuration.

So, it is not allowed to rename a root project's directory? How to correctly rename directory with Maven project?

  1. Project Settings/Modules/ rename into NewName.
  2. NewName
  3. Close project and rename root folder into NewName.
  4. Rename OldName.iml into NewName.iml.

Solution

  • First off, you are using kind of an old version of IDEA, so you may consider upgrading.

    I'm, personally, not that familiar with that particular version of IDE, but in general in IDEA Maven config (pom.xml, settings.xml, etc.) takes precedence over IDEA's native settings.

    In most cases you don't have to do anything when renaming the folder, but if you experiencing issues, close the renamed Project, remove .idea folder and .iml file(s) (if present) and re-import the Project (Open -> double-click the root pom.xml -> Open as Project)