23 June 2018

In a previous post I have described the minimal configuration to get checkstyle working with Gradle. What i did not like, is that I have to place the checkstyle.xml in my project. Assuming I stick with the standard checkstyle.xml from Google or Sun (or I have a corporate one), I do no want to place it in each and every repo.

What I found now is that Gradle supports referencing resources from within published artifacts. In the below configuration, the google_checks.xml is referenced from the published artifact com.puppycrawl.tools:checkstyle:8.10.1 directly.

apply plugin: 'checkstyle'

configurations {
def versions = [
    checkstyle: '8.10.1',
dependencies {
    checkstyleConfig ("com.puppycrawl.tools:checkstyle:${versions.checkstyle}") {
        transitive = false
checkstyle {
    showViolations = true
    ignoreFailures = false
    toolVersion = "${versions.checkstyle}"
    config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')

The example is derived from the offical gradle docs.