Usage

The following examples describe the basic usage of the Checkstyle Plugin.

Generate Checkstyle Report As Part of the Project Reports

To generate the Checkstyle report as part of the Project Reports, add the Checkstyle Plugin in the <reporting> section of your pom.xml.

<project>
  ...
   <reporting>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-checkstyle-plugin</artifactId>
          <version>2.14</version>
          <reportSets>
            <reportSet>
              <reports>
                <report>checkstyle</report>
              </reports>
            </reportSet>
          </reportSets>
        </plugin>
      </plugins>
    </reporting>
  ...
</project>

Then, execute the site phase to generate the report.

mvn site

Generate Checkstyle Report As Standalone

You can also generate the Checkstyle report by explicitly executing the checkstyle:checkstyle goal from the command line. You are not required to specify the Checkstyle Plugin in your pom.xml unless you want to use a specific configuration.

mvn checkstyle:checkstyle

Checking for Violations as Part of the Build

If you want to report to the console or fail the build, you must add an execution of checkstyle::check to the <build> element and configure any options that you need.

(Note in that for Maven 3, as per Maven 3 Compatibility Notes, in Maven 3, options you set in the <reporting> element do not have any effect on executions in the <build> element.)

For example:

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