I'm working on a project where all the team members are using Eclipse and I'm the only IDEA user. This creates a lot of noise from imports rearrangements. The order in which eclipse imports is: Java, Javax, Org, Com, everything else in alphabetical order. Is it possible to configure IDEA to follow these rules?
4 Answers
Some more details: I ended up performing these steps to match out of the box eclipse organizing:
(in Settings
> Editor
> Code Style
> Java
> imports
, as mentioned by @yole)
set "class count to use import with '*'" to 99 (seems like you cannot turn this off)
set this ordering for
Import Layout
(like eclipse defaults):static all other, blank, java.*, blank, javax.*, blank, org.*, blank, com.*, blank, all other imports
FWIW, there is an Intellij plugin called "eclipse code formatter" that I evaluated for this purpose and ended up discarding, because it set up a separate shortcut (in OSX) that was already in use by core IDE functionality.
-
4Eclipse Code Formatter works totally fine, not sure what that shortcut problem was...– MeoMay 19, 2015 at 14:07
-
7As an update, for IntelliJ 14.1 on a Mac, you can find these settings under Preferences -> Editor -> Code Style --> Java --> Imports (tab) Jun 25, 2015 at 14:11
-
Note that you can edit the way the Eclipse Code Formatter order imports and that it overrides anything you change in IntelliJ's settings. Note too that it does not place any imports before java.*– Mafro34Jul 28, 2015 at 19:35
-
2Eclipse Code Formatter overrides stuff, so that it is like in Eclipse, if anything is not right, then it is a bug.– MeoSep 19, 2016 at 22:09
-
1I set up eclipse code formatter including formatting and import order. Sometimes I ended up importing with * although the intellij formatting scheme and the eclipse scheme should not do that (class count 99 ). Currently I imported the eclipse formatter and manually added the imports as above.– ZianJun 17, 2020 at 6:18
Settings | Editor | Code Style | Java | Imports | Import Layout
-
6
In update to Max's answer, the correct order for resolving the checkstyle
warnings. I updated the following in IntelliJ:
static all other,
blank
com.*
java.*
javax.*
org.*
all other imports