Getting Started

Here’s how to use Checkstyle Addons with your standard software.

Checkstyle Addons is distributed via Maven Central and Bintray jcenter, so major build tools can automatically access it.

Checkstyle Addons is compatible with all Checkstyle versions starting from 6.16.1. (Checkstyle Addons v4.2.0 and earlier were also compatible with Checkstyle 6.0 - 6.15.)

Checkstyle Addons uses semantic versioning, so you can always use the latest within a major version, but you should try things out before moving to a higher major version.

Gradle

Checkstyle Addons is available on Maven Central and jcenter, so you can just use it in your Gradle build.
In Gradle, Checkstyle Addons runs as part of the Gradle Checkstyle Plugin. The classpath is extended to include Checkstyle Addons.
Note that the Checkstyle tool version must be specified.

plugins {
    id 'checkstyle'  // regular Checkstyle plugin
}
dependencies {
    checkstyle group: 'com.thomasjensen.checkstyle.addons', name: 'checkstyle-addons', version: '6.0.1'
    //checkstyle group: 'com.thomasjensen.checkstyle.addons', name: 'checkstyle-addons-java8a', version: '6.0.1'
}
checkstyle {
    configFile file('your-checkstyle.xml')
    toolVersion '8.21'             // set Checkstyle version here
    //toolVersion '8.0'      // set Checkstyle version here
}

For the checkstyle-addons dependency, you may also use the version notation version: '6.+' in order to always get the latest compatible version.

Compatibility Notice

The above example is for Checkstyle 8.21 and up. If you are using Checkstyle 7.0 - 8.20, you must instead use the java8a variant of Checkstyle Addons as shown in the commented-out lines of code in the example.

The example above has been tested with Checkstyle toolVersion values up to 8.26. The Gradle build must use at least Java 8.
The older Checkstyle versions 6.16.1 - 6.19 which can run on Java 7, are also supported, but if you set toolVersion to these, you must depend on checkstyle-addons-java7 instead of checkstyle-addons (even if you use Java 8 or higher).

Maven

Checkstyle Addons is available on Maven Central, so you can just use it in your Maven build.
In Maven, Checkstyle Addons runs as part of the Maven Checkstyle Plugin. The classpath is extended to include Checkstyle Addons.
Note that the explicit dependency on Checkstyle itself must also be specified in order to set the correct Checkstyle version.

<project>
  <!-- snip -->
  <properties>
    <!-- path to your checkstyle.xml, relative to the project root -->
    <checkstyle.config.location>your-checkstyle.xml</checkstyle.config.location>
  </properties>
  <!-- snip -->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.17</version>
    <dependencies>
      <dependency>
        <groupId>com.puppycrawl.tools</groupId>
        <artifactId>checkstyle</artifactId>
        <version>8.21</version>    <!-- set Checkstyle version here -->
        <!-- <version>8.0</version> -->
      </dependency>
      <dependency>
        <groupId>com.thomasjensen.checkstyle.addons</groupId>
        <artifactId>checkstyle-addons</artifactId>
        <!-- <artifactId>checkstyle-addons-java8a</artifactId> -->
        <version>6.0.1</version>
      </dependency>
    </dependencies>
  </plugin>
</project>

The example above has been tested with the Checkstyle dependency set to a version up to 8.26. Maven must run at least on Java 8.

Compatibility Notice

The above example is for Checkstyle 8.21 and up. If you are using Checkstyle 7.0 - 8.20, you must instead use the java8a variant of Checkstyle Addons as shown in the commented-out lines of XML in the example.

The older Checkstyle versions 6.16.1 - 6.19 which can run on Java 7, are also supported, but if you use these, you must depend on checkstyle-addons-java7 instead of checkstyle-addons (even if you use Java 8 or higher).

Ant

In Ant, we must add Checkstyle Addons to the classpath of the Checkstyle Ant Task. The Ant task is part of the standard Checkstyle distribution. In order to integrate Checkstyle Addons, the Checkstyle Addons FatJAR is put on the Ant classpath.

Download FatJAR

The FatJAR is simply a JAR which includes Checkstyle Addons along with all its dependencies except Checkstyle itself.

Then, in our Ant build.xml, we declare the Checkstyle task as follows:

<taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties">
    <classpath>
        <pathelement location="lib/checkstyle-8.21-all.jar"/>
        <pathelement location="lib/checkstyle-addons-6.0.1-all.jar"/>
    </classpath>
</taskdef>

The above example is for Checkstyle 8.21 and up. If you are using Checkstyle 7.0 - 8.20, use these lines instead:

<taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties">
    <classpath>
        <pathelement location="lib/checkstyle-8.0-all.jar"/>
        <pathelement location="lib/checkstyle-addons-java8a-6.0.1-all.jar"/>
    </classpath>
</taskdef>

The checkstyle-ant-task.properties is read from checkstyle-8.21-all.jar. The call to the Checkstyle task is standard Ant:

<checkstyle config="/path/to/your-checkstyle.xml">
    <fileset dir="src" includes="**/*.java"/>

    <!-- Where in your build folder to store the cache file used during build for faster analysis -->
    <property key="checkstyle.cache.file" file="target/cachefile"/>
</checkstyle>

For more information on Checkstyle Ant task configuration, please refer to its website.

As with Maven and Gradle, you may use a Java 7 compatible version of Checkstyle Addons by using the -java7 FatJAR (download) and Checkstyle 6.16.1 - 6.19. Checkstyle 7.0 - 8.20 are supported via the java8a-FatJAR.

If you use Ivy for dependency management in Ant, you can take advantage of the fact that Checkstyle Addons is on Maven Central.

IntelliJ IDEA / Android Studio

In IntelliJ IDEA or Android Studio, Checkstyle Addons runs as a third-party addon to the Checkstyle-IDEA plugin. So first make sure you’ve got Checkstyle-IDEA. If not, install via File → Settings… → Plugins → Browse Repostories.

Download FatJAR

After that, you can add Checkstyle Addons to the third-party checks:

Checkstyle Addons in IntelliJ IDEA

Checkstyle-IDEA does not offer a visual editor, so you’ll have to activate the Checkstyle Addons checks by modifying your checkstyle.xml directly.

The Checkstyle Addons version offered by the above download button is compatible with Checkstyle 8.21 and up. If you are using Checkstyle 7.0 - 8.20, use the java8a variant of Checkstyle Addons. If you are using the older Checkstyle versions 6.16.1 - 6.19, use Checkstyle Addons in the java7 variant.

Download "java8a" FatJAR   Download "java7" FatJAR

Eclipse

In Eclipse, Checkstyle Addons runs as an addon to Eclipse-CS. So first make sure you’ve got Eclipse-CS installed at version 7.2.0 or higher. Then:

Download Eclipse Plugin

Installation: Drop the downloaded plugin JAR into the dropins folder of your Eclipse installation and restart Eclipse.

In order to verify that Checkstyle Addons was installed correctly, open the Checkstyle configuration dialog and you should see a new module category named ‘Checkstyle Addons’. Checkstyle Addons fully supports the visual Checkstyle configuration editor of Eclipse-CS:

Checkstyle Addons in Eclipse

The Checkstyle Addons version offered by the above download button is compatible with Checkstyle 8.21 and up. If you are using Checkstyle 7.0 - 8.20, use the java8a variant of Checkstyle Addons. If you are using the older Checkstyle versions 6.16.1 - 6.19, use Checkstyle Addons in the java7 variant.

Download "java8a" Plugin   Download "java7" Plugin

SonarQube

In SonarQube, Checkstyle Addons runs as an extension of the SonarQube Checkstyle Plugin (download, legacy download). Choose your download of Checkstyle Addons for SonarQube depending on the version of the SonarQube Checkstyle Plugin you are using:

The SonarQube rules provided by Checkstyle Addons are tagged with checkstyle-addons, which is useful to filter them from the overall list of Checkstyle rules.

Installation: Drop the downloaded plugin into the extensions/plugins folder of your SonarQube installation (where all the other plugins are). Restart SonarQube.

Command Line

Checkstyle can also be run from the command line. Checkstyle Addons is included by simply adding its FatJAR to the classpath.
The regular JAR is compatible with Checkstyle 8.21 and up (tested up to 8.26). If you are using Checkstyle 7.0 - 8.20, you must use the java8a variant of Checkstyle Addons. If you are using Checkstyle 6.16.1 - 6.19, you must use the java7 variant.

Download regular FatJAR   Download "java8a" FatJAR   Download "java7" FatJAR

Now you can run Checkstyle with Checkstyle Addons like this (example for regular JAR):

java -cp checkstyle-addons-6.0.1-all.jar;checkstyle-8.21-all.jar com.puppycrawl.tools.checkstyle.Main -c your-checkstyle.xml src

The above assumes that your sources are in a subdirectory src, and that the required JARs and your configuration file are in the current directory.