3

我在 3.0.0 版和 Checkstyle 6.18 中使用Maven Checkstyle 插件

这是我的初始配置:

<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 它与 Maven 插件捆绑在一起时,构建成功而没有任何错误(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):我为此提出了一个错误

4

1 回答 1

6

在 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>
于 2018-06-21T09:57:14.163 回答