-
Notifications
You must be signed in to change notification settings - Fork 23
/
checkstyle.gradle
72 lines (63 loc) · 2.21 KB
/
checkstyle.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* https://gist.github.com/kboyarshinov/2857d726d23f8b6cbc19
*
* Checkstyle tasks
* Usage:
* - place this file under root dir of your project at /gradle directory
* - apply script from your gradle file:
* apply from : "{rootDir}/gradle/checkstyle.gradle"
*
* To configure checkstyle use configs at:
* "{rootDir}/config/checkstyle/checkstyle.xml" - for main projects
* "{rootDir}/config/checkstyle/checkstyle-test.xml" - for tests
* "{rootDir}/config/checkstyle/suppresions.xml" - for style suppressions
*
* Xml and HTML reports are stored:
* "{project.buildDir}/reports/checkstyle/"
* HTML styling is done by XSLT stylesheet:
* "{rootDir}/config/checkstyle/checkstyle-noframes-sorted.xsl"
*/
apply plugin: 'checkstyle'
checkstyle {
toolVersion '7.1.1'
configFile = file("${rootProject.rootDir}/config/checkstyle/checkstyle.xml")
}
task checkstyleMain(type: Checkstyle) {
ignoreFailures = false
showViolations = true
source 'src/main', 'src/release'
include '**/*.java'
exclude '**/gen/**'
exclude '**/R.java'
exclude '**/BuildConfig.java'
reports {
xml.destination "$project.buildDir/reports/checkstyle/main.xml"
}
classpath = files()
}
task checkstyleReport doLast {
checkType = project.ext.get("checkType")
if (file("$buildDir/reports/checkstyle/${checkType}.xml").exists()) {
ant.xslt(in: "$project.buildDir/reports/checkstyle/${checkType}.xml",
style: "${rootProject.rootDir}/config/checkstyle/checkstyle-noframes-sorted.xsl",
out: "$project.buildDir/reports/checkstyle/checkstyle_${checkType}.html"
)
}
}
task checkstyle(dependsOn: ['checkstyleMain']) {
description 'Runs Checkstyle inspection against Android sourcesets.'
group = 'Code Quality'
}
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()) {
project.ext.set("checkType", matcher.group(1).toLowerCase())
}
}
checkstyleReport.execute()
}
}
}