Maven检查样式作为构建的一部分

Pau*_*nis 22 java checkstyle maven

如果有checkstyle错误,是否有可能以某种方式迫使maven失败?现在我必须运行site目标来生成javadocscheckstyle报告.我想在install目标上实现它,如果checkstyle有一些错误,我需要构建失败.这有可能实现吗?

现在我有我checkstyle的maven报告块:

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.9.1</version>
            <configuration>
                <configLocation>src/test/resources/checkstyle.xml</configLocation>
            </configuration>
        </plugin>
    </plugins>
</reporting>
Run Code Online (Sandbox Code Playgroud)

hgr*_*rey 29

您需要绑定checkstyle:check到Maven生命周期阶段(例如,验证)并设置failOnViolation为true.

就像是:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.9.1</version>
    <executions>
        <execution>
        <id>checkstyle</id>
        <phase>validate</phase>
        <goals>
            <goal>check</goal>
        </goals>
        <configuration>
            <failOnViolation>true</failOnViolation>
        </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

  • @Jonathan checkstyle实际上默认为验证阶段,而不是验证 (6认同)

小智 5

问题问题可能已经有一段时间了,但这对我不起作用.

对于可能与我有相同问题的任何其他人,尽管存在大量问题,但构建成功,我通过将violationSeverity属性从默认值降低errorwarning插件的configuration块来修复它.