-
Notifications
You must be signed in to change notification settings - Fork 0
/
jacoco.gradle
73 lines (66 loc) · 2.06 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
apply plugin: 'jacoco'
android {
buildTypes {
debug {
/**打开覆盖率统计开关**/
testCoverageEnabled = true
}
}
}
//源代码路径,有多少个module,就在这里写多少个路径,如果你只有app一个module,那么就写一个就可以
def coverageSourceDirs = [
'../src/main/java',
'../src/main/java',
]
//class文件路径,如果你只有app一个module,那么就写一个就可以
def coverageClassDirs = [
'../build/intermediates/javac/debug/classes',
'../build/tmp/kotlin-classes'
]
//Jacoco 版本,建议用这个版本兼容性比较好
jacoco {
toolVersion = "0.8.2"
}
//生成报告task
task jacocoTestReport(type: JacocoReport) {
group = "JacocoReport"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
}
println("-------" + buildDir)
println("-------" + rootDir)
classDirectories.from = files(files(coverageClassDirs).files.collect {
println("$rootDir" + it)
fileTree(dir: "$rootDir" + it,
// 过滤不需要统计的class文件
excludes: ['**/R*.class',
'**/*$InjectAdapter.class',
'**/*$ModuleAdapter.class',
'**/*$ViewInjector*.class'
])
})
sourceDirectories.from = files(coverageSourceDirs)
executionData.from = files("$buildDir/outputs/code-coverage/coverage.ec")
doFirst {
coverageClassDirs.each { path ->
println("$rootDir" + path)
new File("$rootDir" + path).eachFileRecurse { file ->
if (file.name.contains('$$')) {
file.renameTo(file.path.replace('$$', '$'))
}
}
}
}
}
//初始化Jacoco Task
task jacocoInit() {
group = "JacocoReport"
doFirst {
File file = new File("$buildDir/outputs/code-coverage/")
if (!file.exists()) {
file.mkdir();
}
}
}