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

Omindu
1 min readJul 3, 2016

--

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 'xxx.xxx.xxx' 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.

[1] — https://maven.apache.org/plugins/maven-checkstyle-plugin/
[2] — https://www.jetbrains.com/help/idea/2016.1/optimizing-imports.html?origin=old_help

--

--