Maven checkstyle violation count

2.2k views Asked by At

How can I get Checkstyle to print out the total number of found violations when running the maven task? For example right now I just total up the number of violations found after each run.

For clarification, I simply want this at the end of my maven task:

Checkstyle found XXX violations

Checkstyle configuration:

<build>
 <plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-checkstyle-plugin</artifactId>
   <version>2.17</version>
   <executions>
    <execution>  
     <id>checkstyle</id>
      <phase>validate</phase>
      <goals>
       <goal>check</goal>
      </goals>
      <configuration>
       <failOnViolation>true</failOnViolation>
       <configLocation>/path</configLocation>
       <maxAllowedViolations>100</maxAllowedViolations>
      </configuration>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>
2

There are 2 answers

5
S.Roshanth On

Build the project with “mvn checkstyle:checkstyle” command outside the Eclipse. and open the generated checkstyle.html in /Your_Project/target/site folder. You can see the complete report.

0
Zach Pedigo On

There is an alternative way of doing this same thing that would return you the actual number. To do this all you have to do is change the number of allowed violations to 0 and run mvn clean install this should run your checkstyle plugin and eventually fail. It will then display the number of violations compared to the number of allowed violations.