Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven check style as a part of the build

Tags:

Is there a possibility to somehow force maven to fail the build if there are some checkstyle errors? Now I have to run site goal to generate javadocs and checkstyle reports. I want to make it on install goal and if checkstyle has some error I need build to fail. Is this possible to achieve?

Now I have my checkstyle in reporting block of maven:

<reporting>     <plugins>         <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-checkstyle-plugin</artifactId>             <version>2.9.1</version>             <configuration>                 <configLocation>src/test/resources/checkstyle.xml</configLocation>             </configuration>         </plugin>     </plugins> </reporting> 
like image 204
Paulius Matulionis Avatar asked Aug 29 '12 14:08

Paulius Matulionis


People also ask

How do I check my Checkstyle violations?

It will also generate the violation report for the project which is available as a view in Eclipse. To view to violation report, go to Window -> Show View -> Other, and search for Checkstyle. Options for Violations and Violations Chart should be displayed.


1 Answers

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> 
like image 134
hgrey Avatar answered Sep 21 '22 09:09

hgrey