【问题标题】:Checkstyle Maven plugin execution doesn't fail on error when using google_checks使用 google_checks 时,Checkstyle Maven 插件执行不会因错误而失败
【发布时间】:2018-10-07 00:50:06
【问题描述】:

我在 3.0.0 版和 Checkstyle 6.18 中使用 Maven Checkstyle plugin

这是我的初始配置:

<properties>
    <maven.checkstyle.plugin.version>3.0.0</maven.checkstyle.plugin.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>${maven.checkstyle.plugin.version}</version>
            <configuration>
                <failsOnError>true</failsOnError>
                <failOnViolation>true</failOnViolation>
            </configuration>
        </plugin>
    </plugins>
</build>

运行 mvn checkstyle:checkstyle 将导致构建失败,因为存在 checkstyle 错误。这是意料之中的。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (default-cli) on project demo: Failed during checkstyle execution: There are 311 errors reported by Checkstyle 6.18 with sun_checks.xml ruleset. -> [Help 1]

但是,当我使用 google_checks.xml which comes bundled with the Maven plugin 时,构建成功且没有任何错误(target/checkstyle-report.xml 仍然显示问题)。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>${maven.checkstyle.plugin.version}</version>
    <configuration>
        <configLocation>google_checks.xml</configLocation>
        <failsOnError>true</failsOnError>
        <failOnViolation>true</failOnViolation>
    </configuration>
</plugin>

我的期望是当我使用google_checks.xml 配置时构建会失败。我做错了什么?

更新(04.05.2018):我为此提出了a bug

【问题讨论】:

  • 你能验证使用 Checkstyle 的 CLI 和 google 配置会产生违规吗?如果是这样,那么您的 Maven 配置就是问题所在。
  • 我知道 Maven 是问题所在。我试图找出究竟是什么问题,因为它适用于默认的 Sun 检查。运行 Checkstyle CLI 适用于任何配置。

标签: java maven checkstyle maven-checkstyle-plugin


【解决方案1】:

在 google_checks.xml 中,严重性标记为失败。将其更改为错误会导致检查失败。

原文:

<property name="severity" value="warning"/>

更新:

<property name="severity" value="error"/>

在您的 Maven 配置中,您还可以调整失败的严重程度:

<configuration>
    <encoding>UTF-8</encoding>
    <consoleOutput>true</consoleOutput>
    <failsOnError>true</failsOnError>
    <failOnViolation>true</failOnViolation>
    <violationSeverity>warning</violationSeverity>
    <linkXRef>false</linkXRef>
</configuration>

【讨论】:

    猜你喜欢
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 2023-03-17
    相关资源
    最近更新 更多