使用google_checks时,Checkstyle Maven插件执行不会出错

时间:2018-04-26 10:43:56

标签: java maven checkstyle maven-checkstyle-plugin

我在版本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

1 个答案:

答案 0 :(得分:3)

在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>