Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkstyle in Maven project. Cannot fail the project in case of violations

I have a problems with Checkstyle plugin for java. I need to fail the whole multimodule project in case of any violations. In parent pom.xml I have the following

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ss.ita</groupId>
  <artifactId>jresume</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>
  <name>JResume</name>

  <modules>
    <module>common</module>
    <module>persistence</module>
    <module>business</module>
    <module>logging</module>
    <module>web</module>
  </modules>
  <build>

      <plugins>
      <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-checkstyle-plugin</artifactId>
       <version>2.16</version>
       <executions>
         <execution>
           <id>validate</id>
           <phase>validate</phase>
           <configuration>
             <configLocation>dev/checkstyle.xml</configLocation>
             <encoding>UTF-8</encoding>
             <consoleOutput>true</consoleOutput>
             <failsOnError>true</failsOnError>
             <failOnViolation>true</failOnViolation>
           </configuration>
           <goals>
             <goal>check</goal>
           </goals>
         </execution>
        </executions>
       </plugin>
      </plugins>

  </build>
</project>

My checkstyle.xml is placed in dev folder.

When I run my project with

mvn clean install

It prints the list of all violations. But It cannot fail the whole project. It prints SUCCESS for all modules. I tried to use failsOnError and failOnViolation both. But It didn't work.In plugin documentation there are these requirements:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: test.
  • The goal is thread-safe and supports parallel builds.
  • Binds by default to the lifecycle phase: verify.

Where I go wrong. Maybe I wrote my pom.xml in a wrong way. Please help me solve this problem.

like image 989
Luchnik Avatar asked Feb 09 '23 02:02

Luchnik


1 Answers

Probably you forget

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

violationSeverity: The lowest severity level that is considered a violation. Valid values are "error", "warning" and "info".

The default value is error, which means warning will not make maven build fail.

see more details in:

http://maven.apache.org/plugins/maven-checkstyle-plugin/check-mojo.html#violationSeverity

like image 87
Gary Gauh Avatar answered Feb 11 '23 19:02

Gary Gauh