How to compile project with Google Checkstyle rules with gradle?

You can add this configuration into your build.gradle file:

configurations {
  checkstyleOverride
}

dependencies {
  checkstyleOverride('com.puppycrawl.tools:checkstyle:6.11.2')
}

tasks.withType(Checkstyle) {
  checkstyleClasspath = project.configurations.checkstyleOverride
}

Enjoy!


The problem lies in the fact that com.puppycrawl.tools.checkstyle.checks.blocks.EmptyCatchBlockCheck was indeed added to checkstyle but for version 6.4-SNAPSHOT. As it can be seen in checkstyle repository (pom.xml history) version 6.4-SNAPSHOT was introduced on the 02.02.2015 and EmptyCatchBlockCheck class was created on 18.02.2015.

Gradle still uses version 6.3 as in the following log extract:

:checkstyleMain
Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/6.3/checkstyle-6.3.pom

So there's simply no class You'd like to use.

According to the docs checkstyle classpath can be specified with checkstyleClasspath property - you can try to set it up manually.

I've also prepared a demo with 6.4-SNAPSHOT version, it can be found here. Checkstyle jar was built with mvn clean package with source taken from this repo.