Last active
February 22, 2019 17:21
-
-
Save mauricegavin/2fced2dea175898fb1768ae05ac0c303 to your computer and use it in GitHub Desktop.
Using Checkstyle's maxErrors with Gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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