Ksenia
Ksenia

Reputation: 3753

Why can't I rename package in intellij idea?

Why can't I change package name in intellij idea?

I want to change "java" package to something else, for example "junit" or "jtests":

enter image description here

But when I select Refactor -> Rename I wind up with the dialog window:

enter image description here

then I select Rename current, in the next window I enter desired package name:

enter image description here

and then, no matters whether I click Refactor or Preview button, nothing happens. Nothing at all: no errors, no warnings, no actions. Why can't I rename this package?

Upvotes: 2

Views: 5260

Answers (5)

Tohid Makari
Tohid Makari

Reputation: 2484

For me it was due to memory problem, after increasing memory (heap size) it solved.

Upvotes: 0

profimedica
profimedica

Reputation: 2830

Only folders under java are part of the package qualified name.

Example: If you have a file in a folder located under app/src/main/java/com/my/package then the package will be com.my.package

So, you only want to change folders under java.

However, regarding the "com" folder, the IDE does not provide an option to refactor package name. In this case, you need to manually rename all code occurrences of the old folder and invalidate the cache after renaming the folder.

File > Invalidate caches... > Clear system

Upvotes: 0

Ben Ripka
Ben Ripka

Reputation: 440

Just a bug in intellij. Invalidate the caches and restart. Here's how, it's easy.

Upvotes: 0

Sorin Dumitru
Sorin Dumitru

Reputation: 99

For me invalidation didn't work. I made a new package and temporarily moved the classes out of the package I wanted to rename. It would disapear when I would rename them, so I would create them again.

Upvotes: 0

Ksenia
Ksenia

Reputation: 3753

It seems to be a bug of IntelliJ IDEA. I found the solution on JetBrains forum. By invalidating the cache and restarting, I got the ability to rename this package.

Upvotes: 1

Related Questions