-
Notifications
You must be signed in to change notification settings - Fork 0
/
jacoco.gradle
92 lines (83 loc) · 2.44 KB
/
jacoco.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
apply plugin: 'jacoco'
configurations {
jacocoAnt
jacocoRuntime
}
jacoco {
toolVersion = "0.8.2"
reportsDir = file("tests/reports")
}
task instrument(dependsOn: [classes, project.configurations.jacocoAnt]) {
inputs.files classes.outputs.files
File outputDir = new File(project.buildDir, 'instrumentedClasses')
outputs.dir outputDir
doFirst {
project.delete(outputDir)
ant.taskdef(
resource: 'org/jacoco/ant/antlib.xml',
classpath: project.configurations.jacocoAnt.asPath,
uri: 'jacoco'
)
def instrumented = false
if (file(sourceSets.main.java.outputDir).exists()) {
def instrumentedClassedDir = "${outputDir}/${sourceSets.main.java}"
ant.'jacoco:instrument'(destdir: instrumentedClassedDir) {
fileset(dir: sourceSets.main.java.outputDir, includes: '**/*.class')
}
sourceSets.test.runtimeClasspath -= files(sourceSets.main.java.outputDir)
sourceSets.test.runtimeClasspath += files(instrumentedClassedDir)
instrumented = true
}
if (instrumented) {
test.jvmArgs += '-noverify'
}
}
}
test.dependsOn instrument
def jacoco_exclusions = ['src/test/**',
'**/models/**',
'**/resources/**',
'**/config/**']
jacocoTestReport {
reports {
xml.enabled true
csv.enabled true
html.enabled true
html.destination file("tests/reports")
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: jacoco_exclusions)
})
}
}
jacocoTestCoverageVerification {
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it,
exclude: jacoco_exclusions)
})
}
violationRules {
rule {
limit {
counter = "CLASS"
minimum = 0.6
}
limit {
counter = "METHOD"
minimum = 0.6
}
limit {
counter = "BRANCH"
//TODO reduce temporally
minimum = 0.5
}
limit {
counter = "LINE"
minimum = 0.6
}
}
}
}
check.dependsOn jacocoTestCoverageVerification