score:1

Accepted answer

renaming all packages using eclipse:

i tried to rename the packages using eclipse. soon enough i faced the problem with this approach. first merge of master branch in my local branch restored all old packages again. the idea was to rename the packages on a weekend when no one works on the project. but it still would have taken 5+ hours per branch and i had to change at least the master and the last release branch to prevent merge conflicts. i realized that this does not work in my case.

renaming all packages using a custom java program:

i wrote a java program which performs following steps:

  1. in the first iteration through all directories it copied all folders to a new directory with only lowercase names (the first subpackage was completely renamed to prevent problems on windows hosts).
  2. then the program started a second iteration through the new directory and renamed all import packages in java files. for most imports this is quiet simple but i needed to use reflection to correctly rename static imports and imports of enums in java classes e.g import my.package.myclass.myenum.
  3. the next step of the program was to rename all other occurrences of the old package names found in eclipse e.g. testng xml files, ...
  4. the last step was to delete the old folders.

the runtime of the program is about 2 minutes per branch. the updated project compiles and i did not face any issues.


i did not add any code because the program is only working for this project. maybe it still helps someone.

score:0

in my case i use intellij idea ide and refactoring mentioned is lot easier. you just have to right click and change the package name as you mentioned, this will update package name every where this was being used. let me know if it works. see the screenshot for reference

score:0

this can be performed with two steps using an intermediate package name:

  • right-click on the package main.mypackages.utils and select refactor -> rename...
  • enter main.mypackages2.utils2 (check rename subpackages if you have subpackages) and click ok

now repeat the same and rename main.mypackages2.utils2 to main.mypackages.utils.


Related Query