使用checkstyle有一个不错的XPathSuppressionFilter。使用它
添加到您的检查样式.xml文件
<!-- externalize the ignored/suppressed checks -->
<module name="SuppressionFilter">
<property name="file" value="./checkstyle-suppressions.xml" />
<property name="optional" value="false" />
</module>
和检查样式抑制.xml
<!-- disable checks against lombok annotations -->
<suppress-xpath checks="HideUtilityClassConstructor" query="//CLASS_DEF[.//ANNOTATION/IDENT[@text='UtilityClass']]"/>
<suppress-xpath checks="HideUtilityClassConstructor" query="//CLASS_DEF[.//ANNOTATION/IDENT[@text='Getter']]"/>
<suppress-xpath checks="HideUtilityClassConstructor" query="//CLASS_DEF[.//ANNOTATION/IDENT[@text='Setter']]"/>