Getting Started

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

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

Checkstyle Addons is compatible with all Checkstyle versions starting from 6.16.1. (Older versions of Checkstyle Addons were also compatible with even older versions of Checkstyle, down to Checkstyle 6.0.)

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 different major version.

Gradle

Checkstyle Addons is available on Maven Central, 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: '7.0.1'
    //checkstyle group: 'com.thomasjensen.checkstyle.addons', name: 'checkstyle-addons-java8b', version: '7.0.1'
}
checkstyle {
    configFile = file('your-checkstyle.xml')
    toolVersion = '10.0'             // set Checkstyle version here
    //toolVersion = '8.21'      // set Checkstyle version here
}

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

Since the Checkstyle API breaks every now and then, you must use a Checkstyle Addons variant which matches the version of Checkstyle you are using:

Java Checkstyle Checkstyle Addons Variant
≥ 11 ≥ 10.0 normal (no postfix)
≥ 8 8.21 - 9.3 -java8b
≥ 8 7.0 - 8.20 -java8a
≥ 7 6.16.1 - 6.19 -java7
≤ 7 older use Checkstyle Addons v4.x

The example above contains commented-out lines which show how the java8b variant is applied.

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>3.1.2</version>
    <dependencies>
      <dependency>
        <groupId>com.puppycrawl.tools</groupId>
        <artifactId>checkstyle</artifactId>
        <version>10.0</version>    <!-- set Checkstyle version here -->
        <!-- <version>8.21</version> -->
      </dependency>
      <dependency>
        <groupId>com.thomasjensen.checkstyle.addons</groupId>
        <artifactId>checkstyle-addons</artifactId>
        <!-- <artifactId>checkstyle-addons-java8b</artifactId> -->
        <version>7.0.1</version>
      </dependency>
    </dependencies>
  </plugin>
</project>

The example above has been tested with the Checkstyle dependency set to a version up to 10.5.0.

Since the Checkstyle API breaks every now and then, you must use a Checkstyle Addons variant which matches the version of Checkstyle you are using:

Java Checkstyle Checkstyle Addons Variant
≥ 11 ≥ 10.0 normal (no postfix)
≥ 8 8.21 - 9.3 -java8b
≥ 8 7.0 - 8.20 -java8a
≥ 7 6.16.1 - 6.19 -java7
≤ 7 older use Checkstyle Addons v4.x

The example above contains commented-out lines which show how the java8b variant is applied.

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.

The concrete FatJAR needed depends on the version of Checkstyle you are using:

Java Checkstyle Checkstyle Addons Variant
≥ 11 ≥ 10.0 Download normal FatJAR
≥ 8 8.21 - 9.3 Download "java8b" FatJAR
≥ 8 7.0 - 8.20 Download "java8a" FatJAR
≥ 7 6.16.1 - 6.19 Download "java7" FatJAR
≤ 7 older use Checkstyle Addons v4.x

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-10.0-all.jar"/>          <!-- the core Checkstyle FatJAR -->
        <pathelement location="lib/checkstyle-addons-7.0.1-all.jar"/>  <!-- our Checkstyle Addons FatJAR -->
    </classpath>
</taskdef>

The checkstyle-ant-task.properties is read from checkstyle-10.0-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.

If you use Ivy for dependency management in Ant, you can take advantage of the fact that Checkstyle Addons, including its FatJAR, 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.

Next, download a Checkstyle Addons FatJar:

Java Checkstyle Checkstyle Addons Variant
≥ 11 ≥ 10.0 Download normal FatJAR
≥ 8 8.21 - 9.3 Download "java8b" FatJAR
≥ 8 7.0 - 8.20 Download "java8a" FatJAR
≥ 7 6.16.1 - 6.19 Download "java7" FatJAR
≤ 7 older use Checkstyle Addons v4.x

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.

Eclipse

In Eclipse, Checkstyle Addons runs as an addon to Eclipse-CS. So first make sure you’ve got Eclipse-CS installed.

Then download the Checkstyle Addons plugin to match your version of Eclipse-CS:

Java Eclipse-CS Checkstyle Addons Variant
≥ 11 ≥ 10.0 Download Eclipse Plugin
≥ 8 8.21.0 - 9.3.0 Download "java8b" Eclipse Plugin
≥ 8 7.2.0 - 8.20.0 Download "java8a" Eclipse Plugin
≥ 7 6.16.0 - 6.19.1 Download "java7" Eclipse Plugin
≤ 7 older use Checkstyle Addons v4.x

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

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:

Java
Version
SonarQube Checkstyle
Plugin Version
Checkstyle Addons Variant
≥ 11 ≥ 10.0 Download SonarQube Plugin
≥ 8 4.29 - 9.3 Download "java8b" SonarQube Plugin
≤ 8 2.2 - 4.27 use older Checkstyle Addons

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 concrete FatJAR needed depends on the version of Checkstyle you are using:

Java Checkstyle Checkstyle Addons Variant
≥ 11 ≥ 10.0 Download normal FatJAR
≥ 8 8.21 - 9.3 Download "java8b" FatJAR
≥ 8 7.0 - 8.20 Download "java8a" FatJAR
≥ 7 6.16.1 - 6.19 Download "java7" FatJAR
≤ 7 older use Checkstyle Addons v4.x

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

java -cp checkstyle-addons-7.0.1-all.jar;checkstyle-10.0-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 downloaded JARs and your configuration file are in the current directory.