How do I get Checkstyle CustomImportOrder to work with IntelliJ properly?

Default formatting in IntelliJ looks like as follows:

all other imports
<blank line>
javax.* in alphabetical order
java.* in alphabetical order
<blank line>
static imports in alphabetical order

Right now, it is not possible to sort java and javax separately without blank line in-between and that's why you have the violations.

I've raised issue on GitHub to solve that and it will require changes in Checkstyle code.

As a workaround you may add blank line between javax and java in IntelliJ IDEA configuration and then it should be easy to tune Checkstyle to work with that.


Don't split java and javax in separate groups - just let javax stand before java packages.

checkstyle.xml:

...
    <module name="CustomImportOrder">
        <property name="customImportOrderRules" value="THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC"/>
        <property name="sortImportsInGroupAlphabetically" value="true"/>
        <property name="standardPackageRegExp" value="^(java|javax)\."/>
        <property name="separateLineBetweenGroups" value="true"/>
    </module>
...

checkstyleSuppressions.xml

...
<!--  Let javax.* stand before java.* - that's default Idea settings  -->
<suppress checks="CustomImportOrder"
          message="Wrong lexicographical order for 'java\.[^']+' import\. Should be before 'javax\.[^']+'\."/>
...

You can also omit properties that match default values (standardPackageRegExp and separateLineBetweenGroups for today) - please check actual documentation.