Skip to content

Instantly share code, notes, and snippets.

@mauricegavin
Last active February 22, 2019 17:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricegavin/2fced2dea175898fb1768ae05ac0c303 to your computer and use it in GitHub Desktop.
Save mauricegavin/2fced2dea175898fb1768ae05ac0c303 to your computer and use it in GitHub Desktop.
Using Checkstyle's maxErrors with Gradle
task checkstyle(type: Checkstyle) {
configFile rootProject.file('checkstyle.xml')
configFile file("${project.rootDir}/code_quality_tools/checkstyle.xml")
ignoreFailures true // Uncomment to fail where warnings > 0
showViolations true
source 'src'
include '**/*.java''
classpath = files()
// Allow a threshold of errors.
// Inspired by http://bit.ly/2cCLrTr
def maxErrors = 210 // aim to eventually reduce this to 0
doLast {
reports.all { report ->
def outputFile = report.destination
if (outputFile.exists()) {
def count = outputFile.text.count("<error ")
if (count > maxErrors) {
throw new GradleException("There were $count checkstyle warnings! For more info check $outputFile")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment