简体   繁体   English

Checkstyle 找不到 suppressions.xml

[英]Checkstyle can't find suppressions.xml

I'm using Gradle 5.0 and Checkstyle 8.15.我正在使用 Gradle 5.0 和 Checkstyle 8.15。 I have a Java project with the following Checkstyle config and suppressions files:我有一个带有以下 Checkstyle 配置和抑制文件的 Java 项目:

  • config/checkstyle/checkstyle.xml配置/checkstyle/checkstyle.xml
  • config/checkstyle/suppressions.xml配置/checkstyle/suppressions.xml

checkstyle.xml references suppressions.xml like so: checkstyle.xml像这样引用suppressions.xml

<module name="SuppressionFilter">
    <property name="file" value="config/checkstyle/suppressions.xml"/>
</module>

If I run checkstyle against my source, it fails:如果我对源代码运行 checkstyle,它会失败:

$./gradlew checkstyleMain -xwebpack $./gradlew checkstyleMain -xwebpack

  • Configure project: Defaulting to dev Spring profile配置项目:默认开发 Spring 配置文件

    Task:checkstyleMain FAILED任务:checkstyleMain 失败

FAILURE: Build failed with an exception.失败:构建失败,出现异常。

What went wrong: Execution failed for task ':checkstyleMain'.出了什么问题:任务 ':checkstyleMain' 执行失败。 Unable to create Root Module: config {/Users/robert/dev/...}, classpath {/Users/robert/dev/...}.无法创建根模块:配置 {/Users/robert/dev/...},类路径 {/Users/robert/dev/...}。

Try: Run with --stacktrace option to get the stack trace.尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output.使用 --info 或 --debug 选项运行以获得更多日志输出。 Run with --scan to get full insights.使用 --scan 运行以获得完整的见解。

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.此构建中使用了已弃用的 Gradle 功能,使其与 Gradle 6.0 不兼容。 Use '--warning-mode all' to show the individual deprecation warnings.使用“--warning-mode all”来显示各个弃用警告。 See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings请参阅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在 1 秒内构建失败 3 个可操作任务:1 个已执行,2 个是最新的

If I remove the reference to suppressions.xml , the build completes (checkstyle finds errors that would have been ignored if the suppressions were discovered).如果我删除对suppressions.xml的引用,则构建完成(checkstyle 发现如果发现抑制会被忽略的错误)。

My understanding from the doc is that the root for referenced files like config/checkstyle/suppressions.xml is the project root.我从文档中了解到,像config/checkstyle/suppressions.xml这样的引用文件的根是项目根。 That doesn't seem to be the case however.然而,情况似乎并非如此。

Am I not setting up checkstyle properly?我没有正确设置 checkstyle 吗?

If you are placing suppressions.xml inside project-dir/config/checkstyle/, please use the following way,如果您将 suppression.xml 放在 project-dir/config/checkstyle/ 中,请使用以下方式,

<module name="SuppressionFilter">
    <property name="file" value="${config_loc}/suppressions.xml"/>
</module>

Latest version of checkstyle has config_loc variable set as project-dir/config/checkstyle/ automatically.最新版本的 checkstyle 自动将 config_loc 变量设置为 project-dir/config/checkstyle/。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM