216

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?

rgrinberg
  • 9,638
  • 7
  • 27
  • 44

4 Answers4

397

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.

temporary_user_name
  • 35,956
  • 47
  • 141
  • 220
Max
  • 11,377
  • 5
  • 24
  • 15
  • 4
    [Eclipse Code Formatter](https://plugins.jetbrains.com/plugin/?idea&id=6546) works totally fine, not sure what that shortcut problem was... – Meo May 19 '15 at 14:07
  • 7
    As an update, for IntelliJ 14.1 on a Mac, you can find these settings under Preferences -> Editor -> Code Style --> Java --> Imports (tab) – Matt Passell Jun 25 '15 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.* – Mafro34 Jul 28 '15 at 19:35
  • 2
    Eclipse Code Formatter overrides stuff, so that it is like in Eclipse, if anything is not right, then it is a bug. – Meo Sep 19 '16 at 22:09
  • You can switch the eclipse code formatter as default one with the "Switch code formatter" action. Saying so I still don't know the best solution – keiki Feb 13 '17 at 10:45
  • Note to disable start imports you just remove the java.util and other packages from the table below – tomaytotomato Jan 10 '19 at 14:44
  • 1
    I 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. – Zian Jun 17 '20 at 06:18
49

Settings | Editor | Code Style | Java | Imports | Import Layout

Julien
  • 1,765
  • 20
  • 26
yole
  • 92,896
  • 20
  • 260
  • 197
5

The best way is to use Eclipse Code Formatter plugin.

Meo
  • 12,020
  • 7
  • 45
  • 52
0

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
Abhishek Balani
  • 3,827
  • 2
  • 24
  • 34