Maven check style as a part of the build

夙愿已清 提交于 2019-12-02 22:17:18
hgrey

You need to bind checkstyle:check to a Maven lifecycle phase (e.g. validate ) and set failOnViolation to true.

Something like:

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

It might have been some time since the question was asked, but this wasn't working for me.

For anyone else that might be having the same issue as me, with the build succeeding despite a multitude of issues, I fixed it by lowering the violationSeverity property from its default error to warning in the plugin's configuration block.

Even though it has been a long time since this was asked, I did run into another problem:

JavadocMethod: Unable to get class information for @throws tag 'X'.

I solved this by changing the phase from "validate" to "test" so that checkstyle runs after the compile phase.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!