Automatically grouping imports in intelliJ IDEA
Asked Answered
S

0

8

I want to group imports by packages in intelliJ.

Right now it sorts the imports properly, and gives me this.

import com.google.common.Something
import com.google.common.SomethingElse
import org.apache.commons.Something
import org.apache.commons.SomethingElse

I want it to be

import com.google.common.Something
import com.google.common.SomethingElse

import org.apache.commons.Something
import org.apache.commons.SomethingElse

How can I make intelliJ automatically do this, without having to set the package names individually in Editor->Cody Style->Java->Imports->Import Layout.

Subordinary answered 17/7, 2015 at 21:28 Comment(5)
This is not possible. What I suggest you to do instead is to enable import folding and "Auto import on the fly" in IntelliJ IDEA and to forget forever about the layout, grouping or any other details of your import statements. You've got plenty of important things to worry about, and imports are not one of them; the IDE can take care of them perfectly fine.As
The problem is my team formats their code like that. And with intellij "Auto import on the fly" changes the order of imports, thus increasing the size of the diff.Subordinary
I'm fairly certain that your team also has more important things to worry about. "Auto import on the fly" puts imports in a deterministic order (sorted alphabetically), so it won't change anything if everyone sticks to the same convention.As
Yeah, you're probably right. It was just bugging me.Subordinary
That's a pity (or PITA?) that this is not possible, as the Checkstyle Google rules expect it: github.com/checkstyle/checkstyle/blob/master/src/main/resources/…Oospore

© 2022 - 2024 — McMap. All rights reserved.