Fork me on GitHub

Configure Checkstyle

You can configure checkstyle by creating/importing your Checkstyle Check Configuration in Eclipse and then in your pom specify:

  • additionalBuildcommands
  • additionalProjectnatures
  • additionalConfig to create the .checkstyle file.

See the example below, make sure you specify the correct value in check-config-name.

<project>
  [...]
  <build>
    [...]
    <plugins>
      [...]
       <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-eclipse-plugin</artifactId>
          <version>2.10</version>
          <configuration>
            <additionalBuildcommands>
              <buildcommand>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</buildcommand>
            </additionalBuildcommands>
            <additionalProjectnatures>
              <projectnature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</projectnature>
            </additionalProjectnatures>
            <additionalConfig>
              <file>
                <name>.checkstyle</name>
                <content>
                  <![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true">
    <fileset name="all" enabled="true" check-config-name="<YOUR CHECKSTYLE CONFIG NAME HERE>" local="false">
        <file-match-pattern match-pattern="." include-pattern="true"/>
    </fileset>
    <filter name="NonSrcDirs" enabled="true"/>
</fileset-config>
]]>
                </content>
              </file>
            </additionalConfig>
          </configuration>
        </plugin>
      [...]
    </plugins>
    [...]
  </build>
  [...]
</project>