Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Checkstyle Plugin doesn't fail during build even though `failsOnError` is set to `true`

My project enforces strict style so I have the maven-checkstyle-plugin running as part of my build.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <version>${maven-checkstyle.version}</version> // 3.0.0
  <executions>
    <execution>
      <id>checkstyle</id>
      <phase>validate</phase>
      <goals>
        <goal>check</goal>
      </goals>
      <configuration>
        <configLocation>google_checks.xml</configLocation>
        <encoding>UTF-8</encoding>
        <consoleOutput>true</consoleOutput>
        <failsOnError>true</failsOnError>
      </configuration>
    </execution>
  </executions>
</plugin>

When I run the build, I see the plugin running and checking style but it should fail when there are checkstyle issues since I have the true flag set.

Any reason it keeps going and the build succeeds?

[INFO] --- maven-checkstyle-plugin:3.0.0:check (checkstyle) @ demo-api ---
[INFO] Starting audit...
...
...
[WARN] /Users/jeeves/git/jeeves/demo/src/main/java/com/demo/api/routes/UserRoutes.java:9:57: Parameter name 'BASE_PATH' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'. [ParameterName]
[WARN] /Users/jeeves/git/jeeves/demo/src/main/java/com/demo/api/routes/UserRoutes.java:13: Line is longer than 100 characters (found 102). [LineLength]
Audit done.
...
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.153 s
[INFO] Finished at: 2018-08-24T09:53:57-04:00
[INFO] Final Memory: 37M/806M
[INFO] ------------------------------------------------------------------------
like image 989
user2490003 Avatar asked Aug 24 '18 13:08

user2490003


1 Answers

Read the log:

[WARN] /Users/jeeves/git/jeeves/demo/src/main/java/com/demo/api/routes/UserRoutes.java:9:57: Parameter name 'BASE_PATH' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'. [ParameterName]
[WARN] /Users/jeeves/git/jeeves/demo/src/main/java/com/demo/api/routes/UserRoutes.java:13: Line is longer than 100 characters (found 102). [LineLength]
Audit done.

Those are warnings and not the errors, so <failsOnError>true</failsOnError> will not trigger.

Adding the following lines into configuration should change the behavior:

<violationSeverity>warning</violationSeverity>
<failOnViolation>true</failOnViolation>        <!-- defaults as true, can be omitted -->

See the documentation of maven-checkstyle-plugin-2.16:

  • violationSeverity defines the level of violation severity.
  • failOnViolation triggers "fail" event when the violation occurs.
like image 60
Nikolas Charalambidis Avatar answered Oct 26 '22 07:10

Nikolas Charalambidis