mal
mal

Reputation: 3204

How can I specify the order of imports in intellij IDEA?

Intellij keeps reordering my imports like so:

import app.v1.myModule.db.model.InternalError;
import app.v1.myModule.db.model.*;

Whereas our maven checkstyle wants the order like so:

import app.v1.myModule.db.model.*;
import app.v1.myModule.db.model.InternalError;

I should also point out, that this doesn't apply to all the imports, only some of them. I'd like to set it so intellij organises all packages that end with a * to be sorted above fully qualified imports on the same path?

So like this:

import app.v1.myModule.db.model.*;
import app.v1.myModule.db.model.InternalError;
import app.v1.myModule.service.*;
import app.v1.myModule.service.MyService;

For the record, the extra classes are added when the import is ambiguous, so we can't use the * for those particular classes.

Here is a screenshot of how my settings currently look:
enter image description here

Upvotes: 1

Views: 3202

Answers (2)

Egor Klepikov
Egor Klepikov

Reputation: 5809

Try using the following layout for imports with *:

enter image description here

Upvotes: 2

Dan Serb
Dan Serb

Reputation: 145

In IntelliJ you can go to settings -> code style -> java -> Imports Tab

There you have the Imports layout, where you can set up your needed settings.

Upvotes: 1

Related Questions