-
Notifications
You must be signed in to change notification settings - Fork 56
/
build.jacoco-test-report.gradle
75 lines (63 loc) · 2.85 KB
/
build.jacoco-test-report.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
apply plugin: "jacoco"
apply plugin: 'com.github.kt3k.coveralls'
jacoco {
toolVersion = projectJacocoVersion
}
task configureCoverageReport {
doFirst {
def includeAppSrc = false;
def includeCoreSrc = false;
def includeDatabaseSrc = false;
def coverageFiles = []
def coverageSourceDirs = []
// exclude generated classes from code coverage report because not all generated methods will be used
def defaultExcludes = ['**/R.class', '**/R$*.class', '**/BuildConfig.class' // generated by android
, '**/*_*' // generated by androidannotaions
, '**/*InjectAdapter.class', '**/*ModuleAdapter*.class' // generated by dagger
, '**/database/provider/*' // generated database handling
]
// Don't take not existing coverage report files or the report will be empty
def currentCoverageFile = 'app/build/jacoco/testDebugUnitTest.exec'
if (file(currentCoverageFile).exists()) {
println "found app unit test coverage"
includeAppSrc = true;
coverageFiles += currentCoverageFile
}
currentCoverageFile = 'appIt/build/outputs/code-coverage/connected/coverage.ec'
if (file(currentCoverageFile).exists()) {
println "found app integration test coverage"
includeAppSrc = true;
coverageFiles += currentCoverageFile
}
currentCoverageFile = 'appCt/build/jacoco/testDebug.exec'
if (file(currentCoverageFile).exists()) {
println "found app component test coverage"
includeAppSrc = true;
coverageFiles += currentCoverageFile
}
// Don't include classes from modules we haven't executed
if (includeAppSrc) {
coverageSourceDirs += 'app/src/main/java'
tasks.jacocoTestReport.classDirectories += fileTree(dir: 'app/build/intermediates/classes/debug', excludes: defaultExcludes)
}
tasks.jacocoTestReport.additionalSourceDirs = files(coverageSourceDirs)
tasks.jacocoTestReport.executionData = files(coverageFiles)
// Send code coverage report to coveralls with coveralls-gradle-plugin. To get the plugin working
// we need to include the coverageSourceDirs as main sources. But this conflicts with android
// studio and also with jacocoTestReport task.
coveralls {
if (isCi) { // avoid android studio source root conflicts
sourceSets.main.java.srcDirs += coverageSourceDirs
}
}
}
}
compileJava.enabled = false
tasks.jacocoTestReport.dependsOn tasks.configureCoverageReport
tasks.coveralls.dependsOn tasks.configureCoverageReport
jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
}