gradle checkstyle just output warn, but build sucess

Sorry for grave-digging but I just stumbled across this while trying to achieve the same thing. Turns out that this has now been implemented, but requires a tiny configuration change.

So for any future adventures finding their way here: in your build.gradle to the following:

checkstyle {
  ignoreFailures = false
  maxWarnings = 0
}

This will then cause your builds to fail on Checkstyle errors.


EDIT: There is better solution since I wrote that answer -> use maxErrors=0 as xxSwordy mentioned here https://stackoverflow.com/a/57141028/3464596.

Here is PR: https://github.com/gradle/gradle/pull/3901

There is possible to do it for errors by:

ignoreFailures = false

For warnings, there IS NOT POSSIBLE to do that, see [this][1] ticket.

From their old Jira and new GitHub issue comments there is one workaround:

tasks.withType(Checkstyle).each { checkstyleTask ->
    checkstyleTask.doLast {
        reports.all { report ->
            def outputFile = report.destination
            if (outputFile.exists() && outputFile.text.contains("<error ")) {
                throw new GradleException("There were checkstyle warnings! For more info check $outputFile")
            }
        }
    }
}

So answer is: This is not possible by default and there is still opened ticket for that. If you really WANT IT, you can try to participate and try to fix it, Gradle is opensource and it depends on developers :) [1]: https://github.com/gradle/gradle/issues/881