intellij-idearefactoring

How to replace package path easily?


Project/
├── a/
│   ├── core/
│   │   └── com.blabla.hi.sofbs
│   └── api/
│       └── com.blabla.hi.sofbs
└── b/
    ├── core/
    │   └── com.blabla.hi.sofbq
    └── api/
        └── com.blabla.hi.sofbq

to

Project/
├── a/
│   ├── core/
│   │   └── us.bla.sofbs
│   └── api/
│       └── us.bla.sofbs
└── b/
    ├── core/
    │   └── us.bla.sofbq
    └── api/
        └── us.bla.sofbq

I want to refactor packages in my project modules but I don't want to refactor each package one by one because the project has many modules. How can I do this quickly and easily?


Solution

  • To rename packages in IntelliJ IDEA, right-click the package you want to rename in the Project tool window, and from the context menu select Refactor | Rename (Shift + F6). If the package you want to rename represents multiple directories, IntelliJ IDEA will give you the option to rename "Selected directories only" or "All directories".

    Rename Package Directories

    For more information, see the documentation: