Skip to content

Instantly share code, notes, and snippets.

@skhatri
Created February 24, 2012 00:45
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save skhatri/1896321 to your computer and use it in GitHub Desktop.
Save skhatri/1896321 to your computer and use it in GitHub Desktop.
Gradle Checkstyle HTML Reporting
apply plugin: 'checkstyle'
checkstyleMain {
ignoreFailures = false
reports {
include ( '**/*.java')
xml {
destination "${rootProject.buildDir}/reports/checkstyle/main.xml"
}
}
configFile = file('./config/checkstyle/checkstyle.xml')
}
checkstyleTest {
ignoreFailures = false
reports {
include ( '**/*.java')
xml {
destination "${rootProject.buildDir}/reports/checkstyle/test.xml"
}
}
configFile = file('./config/checkstyle/checkstyle-test.xml')
}
task checkstyleReport << {
if (file("$buildDir/reports/checkstyle/${checkType}.xml").exists()) {
ant.xslt(in: "$buildDir/reports/checkstyle/${checkType}.xml",
style:"config/checkstyle/checkstyle.xsl",
out:"$buildDir/reports/checkstyle/checkstyle_${checkType}.html"
)
}
}
task quality(dependsOn:['checkstyleMain', 'checkstyleTest'])
gradle.taskGraph.afterTask {Task task, TaskState state ->
if(state.failure) {
if (task.name in ['checkstyleMain', 'checkstyleTest']) {
checkstyleReport {
def matcher = task.name =~ /^checkstyle(.*)$/
if (matcher.matches()) {
checkType = matcher.group(1).toLowerCase()
}
}
checkstyleReport.execute()
}
}
}
@stephanenicolas
Copy link

Thx for the checkstyle report task. Very useful. It's a pity the gradle plugin doesn't support it out of the box.

@sschuberth
Copy link

IMHO this looks slightly more polished.

@stephanenicolas
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment