Using an Inline Checkstyle Checker Configuration

Since version 2.12, an inlined Checker configuration can be defined directly in the configuration section of the plugin itself inside your pom.xml.

This is especially useful when the Checkstyle checks should be executed with every compile and you do not like to create an own project for your Checkstyle rules and neither like to have a separate parent POM structure.

To define a custom Checkstyle checker configuration inside your pom.xml, use the checkstyleRules parameter.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.16</version>
        <executions>
          <execution>
            <id>verify-style</id>
            <phase>process-classes</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <logViolationsToConsole>true</logViolationsToConsole>
          <checkstyleRules>
            <module name="Checker">

              <!-- Checks for Size Violations.                    -->
              <!-- See http://checkstyle.sf.net/config_sizes.html -->
              <module name="FileLength">
                <property name="max" value="3500" />
                <property name="fileExtensions" value="java"/>
              </module>

              <!-- Checks for whitespace                               -->
              <!-- See http://checkstyle.sf.net/config_whitespace.html -->
              <module name="FileTabCharacter"/>

              <module name="TreeWalker">
                <module name="StaticVariableName"/>
                <module name="TypeName">
                  <property name="format" value="^_?[A-Z][a-zA-Z0-9]*$"/>
                </module>
              </module>
            </module>
          </checkstyleRules>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>