4

Beside mvn test and the build process I want to run Maven and it should fail on violations. I tried different options in pom.xml but nothing worked. failOnViolation and failsOnError didn't help.

I can run mvn checkstyle:check and it outputs the errors to the console (suing <consoleOutput>true</consoleOutput>). But how can I run checkstyle and let it fail on violations?

This is what I tryied so far:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                    <consoleOutput>true</consoleOutput>
                    <failsOnError>true</failsOnError>
                    <failOnViolation>true</failOnViolation>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

2 Answers 2

3

The correct way to do it is by modifying the violationSeverity value.

<configuration>
    <violationSeverity>warning</violationSeverity>
    ...
</configuration>

This setup the lowest severity level that is considered a violation. Valid values are "error", "warning" and "info". More information: https://maven.apache.org/plugins/maven-checkstyle-plugin/check-mojo.html

2

I'm not sure if this is the best way but I got it working. In checkstyle.xml the severity level is set to "warning". I switched to "error" and now the build fails on checkstyle violations.

<module name="Checker">
    <property name="severity" value="error"/>
...
</module>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.