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.
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.
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.
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.
The example above has been tested with the Checkstyle dependency set to a version up to 10.14.1.
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.
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:
The checkstyle-ant-task.properties is read from checkstyle-10.0-all.jar. The call to the Checkstyle task is standard Ant:
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.
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-IDEA does not offer a visual editor, so you’ll have to activate the Checkstyle Addons checks by modifying your checkstyle.xml directly.
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:
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.
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.