我正在使用 Gradle 5.0 和 Checkstyle 8.15。我有一个带有以下 Checkstyle 配置和抑制文件的 Java 项目:
checkstyle.xml
引用 suppressions.xml
像这样:<module name="SuppressionFilter">
<property name="file" value="config/checkstyle/suppressions.xml"/>
</module>
如果我对我的源运行 checkstyle,它会失败:
$ ./gradlew checkstyleMain -xwebpack
Configure project : Defaulting to dev Spring profile
Task :checkstyleMain FAILED
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':checkstyleMain'. Unable to create Root Module: config {/Users/robert/dev/...}, classpath {/Users/robert/dev/...}.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
- Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s 3 actionable tasks: 1 executed, 2 up-to-date
如果我删除对
suppressions.xml
的引用, 构建完成(checkstyle 发现如果发现抑制会被忽略的错误)。我对文档的理解是引用文件的根目录,如
config/checkstyle/suppressions.xml
是项目根。然而,情况似乎并非如此。我没有正确设置 checkstyle 吗?
最佳答案
如果你在 project-dir/config/checkstyle/中放置抑制.xml,请使用以下方式,
<module name="SuppressionFilter">
<property name="file" value="${config_loc}/suppressions.xml"/>
</module>
最新版本的 checkstyle 将 config_loc 变量自动设置为 project-dir/config/checkstyle/。
关于java - Checkstyle 找不到抑制.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53806917/