Custom import order not behaving as expected

39 views
Skip to first unread message

Björn Lindahl

unread,
May 15, 2022, 4:24:17 AM5/15/22
to checkstyle
Hi, I'm experiencing issues with getting CustomImportOrder working properly. I have theese imports

```
import se.pkg1.pkgA.pkgX.SomeClass1 // #1
import se.pkg1.pkgA.pkgX.SomeClass2 // #2

import se.pkg1.pkgB.pkgNotX.SomeClassX // #3
```
My CustomImportOrder definition looks like this:
```<module name="CustomImportOrder">
            <property name="severity" value="error"/>
            <property name="customImportOrderRules"                      value="STANDARD_JAVA_PACKAGE###THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###SAME_PACKAGE(3)###STATIC"/>
            <property name="standardPackageRegExp" value="java|javax|jakarta"/>
            <property name="thirdPartyPackageRegExp" value=" se.pkg1.pkgA"/>
            <property name="specialImportsRegExp" value="se.pkg1"/>
            <property name="sortImportsInGroupAlphabetically" value="true"/>
            <property name="separateLineBetweenGroups" value="true"/>
        </module> 
My interpretation and also how the IntelliJ Checkstyle plugin order the imports is that packages in se.pkg1.pkgA falls within THIRD_PARTY_PACKAGE and so #1 and #2 above is grouped together. 

#3 on the other hand falls within SPECIAL_IMPORTS and should be grouped separate, below THIRD_PARTY_PACKAGE. The problem is though that if I import checkstyle config in IntelliJ java imports it seem to work as expected but when I run the 
maven-checkstyle-plugin it think all three imports should belong to the same group as this:

```
import se.pkg1.pkgB.pkgNotX.SomeClassX // #3
import se.pkg1.pkgA.pkgX.SomeClass1 // #1
import se.pkg1.pkgA.pkgX.SomeClass2 // #2
```
Which is the correct order you'd say?
Thanks!
/Björn


Björn Lindahl

unread,
May 15, 2022, 4:27:07 AM5/15/22
to checkstyle
Sorry, I messed up the code formatting. Maybe some moderator can fix it making it more readable.
Reply all
Reply to author
Forward
0 new messages