Siddhartha
Siddhartha

Reputation: 4464

IntelliJ not respecting import ordering on 'Optimizing imports'

I have an import ordering setup in IntelliJ:

enter image description here

But when I do Ctrl + alt + O to optimize my imports, it shoves the google imports on top followed by the company imports and does not insert a blank line either. Anything I'm missing here?

Upvotes: 2

Views: 2108

Answers (2)

binoternary
binoternary

Reputation: 1915

Notice how the import packages are displayed:
import com.company.*.* and import com.google.*.*
vs
import java.* and import javax.*

When you specify the package name do not add .* at the end (i.e you have written com.company.*, but you should write com.company instead).

Upvotes: 2

user65839
user65839

Reputation:

There is a bug listed in IntelliJ's IDEA's bug tracker IDEA-142468 which I believe describes this issue. It appears to particularly not work well when attempting to list static imports first. Unfortunately, I don't see much of a resolution or workaround within that ticket.

While these aren't completely satisfying, here's what I suggest:

  1. Voting for that issue within IDEA's bug tracker system, and perhaps commenting referencing your screenshots of your configuration and how it isn't working for you, if you think doing so may help them understand the conditions of the problem.
  2. Somehow dealing with the problem until the bug is fixed, either by seeing if it's acceptable to your team to have the static imports at the bottom (assuming that it fixes the problem), or otherwise using IDEA's default import ordering. (Which is pretty lousy suggestion, I admit, I'm just not sure what else to suggest if IntelliJ IDEA isn't working and you want to continue using it.)
  3. If you have a support contract with Jetbrains, you could try contacting support to see if they have further suggestions, and to ensure that they know how this bug is affecting your productivity using their tools.

Upvotes: 1

Related Questions