如何让 Checkstyle CustomImportOrder 正确使用 IntelliJ?
2022-09-03 14:46:11
我正在尝试让Checkstyle(通过maven-checkstyle-plugin)通过使用Checkstyle CustomImportOrder模块来检查我的IntelliJ导入。尽管根据IntelliJ的默认规则订购了我的进口,但Checkstyle仍然说进口订单是错误的。
这是我的导入(根据IntelliJ规则(ctrl + o)排序):
import org.codehaus.jackson.JsonNode;
import javax.sql.rowset.serial.SQLOutputImpl;
import java.util.ArrayList;
import java.util.List;
以下是来自 Checkstyle 的警告消息:
[WARNING] src\main\java\com\example\hej\EnKlass.java[5] (imports) CustomImportOrder: Import statement is in the wrong order. Should be in the 'SPECIAL_IMPORTS' group.
[WARNING] src\main\java\com\example\hej\EnKlass.java[6] (imports) CustomImportOrder: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.
[WARNING] src\main\java\com\example\hej\EnKlass.java[7] (imports) CustomImportOrder: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.
这是我的checkstyle.xml CustomImportOrder规则(由Checkstyle网站推荐给IntelliJ):
<module name="CustomImportOrder">
<property name="customImportOrderRules" value="THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC"/>
<property name="specialImportsRegExp" value="^javax\."/>
<property name="standardPackageRegExp" value="^java\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="false"/>
</module>
这里可能有什么问题?我一直试图改变规则,但没有运气。我也试图删除/操纵正则表达式,但没有运气。