Configuring Intellij IDEA to overcome Checkstyle ‘Wrong order for import’ issues

If you have integrated the Maven Checkstyle Plugin [1], you are most likely to encounter build failures during checkstyle execution with the message:

'Wrong order for '' import'

If you are developing in IDEA, even if you optimize imports [2], you are most likely to get this error due to the ordering of java and javax imports. The problem is, by default IDEA order the javax imports after java imports (in version 13 and 14 at least). At first you try to fix this by manually arranging the imports, but it gets kinda annoying when this happens frequently. Luckily there is a way we can fix this by configuring IDEA to satisfy the checkstyle requirements.

Open the ‘Settings‘ (or ‘Preferences‘ in mac) window and goto Editor > Code Style > Java. Click on ‘Imports‘ tab. In ‘Import Layout‘ area, you can arrange the import order by selecting the import type and clicking on the arrow (see image below). Once the changes are done apply the new settings. Now IDEA will make the import optimization according to the new configurations.

Screen Shot 2016-04-26 at 5.29.16 PM


[1] –
[2] –