Skip to content
Advertisement

Moving packages in IntelliJ IDEA

I have a problem moving packages in IntelliJ IDEA. I have created Maven project with multiple modules and each of those modules has a package with the same name. Now whole project becomes a mess if I try to rename some of the packages.

My current project structure is something like this:

--parent-module
  |
  |--module-one
  |  |--src
  |     |--main
  |        |--java
  |           |--somepackage
  |              |--someotherpackages
  |--module-two
  |  |--src
  |     |--main
  |        |--java
  |           |--somepackage
  |              |--somemorepackages
  |--module-three
     |--src
        |--main
           |--java
              |--somepackage
                 |--someevenmorepackages

Notice that somepackage is present in all maven modules.

After MANY created classes in all of those modules and packages I have finally realised what have I done. Now I need to put somepackage into another package under java so I can have something like com.example.moduleone.somepackage.

I have tried renaming package but it renames it in all modules and that creates hailstorm of errors in the code. Also, IntelliJ IDEA renames it to com.example.moduleone.somepackage in all of the modules.

Any help would be highly appreciated.

Advertisement

Answer

Might be easiest to create the new package first and then move the classes you want to move into it and then delete somepackage once everything have been moved around

So first add moduleone, then move all of the classes you want to move, then do the same for the other modules, then delete somepackage

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement