java - Checkstyle 找不到抑制.xml

标签 java gradle checkstyle

我正在使用 Gradle 5.0 和 Checkstyle 8.15。我有一个带有以下 Checkstyle 配置和抑制文件的 Java 项目:

  • 配置/checkstyle/checkstyle.xml
  • config/checkstyle/suppressions.xml
  • 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.

    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/

    相关文章:

    java - 如何使用 Java 正则表达式提取以下数据?

    java - 如何配置一个eclipselink JTA序列连接池

    java - 安卓工作室-混淆器 "java.io.IOException ...bin\classes (No such file or directory)"

    java - Findbugs、PMD 或 Checkstyle 规则来查找字段的访问权限

    maven - 如何外部化 maven-checkstyle-plugin 的 checkstyle 配置

    java - 在java中仅使用灰度值数组绘制图像

    java - Axis2 测试客户端错误

    checkstyle - Java checkstyle,魔数(Magic Number)检查

    android - 错误 :In <declare-styleable> SherlockSpinner, 找不到属性 android:popupPromptView

    android-studio - 等待 30 秒 com.google.common.util.concurrent.SettableFuture@1e023601[status=PENDING]