2017-08-09 21:56:20 +02:00
|
|
|
apply plugin: 'jacoco'
|
|
|
|
|
2018-09-11 22:21:55 +02:00
|
|
|
jacoco {
|
|
|
|
toolVersion(versions.jacoco)
|
|
|
|
}
|
|
|
|
|
2018-10-07 20:45:20 +02:00
|
|
|
def mergedJacocoExec = file("${project.buildDir}/jacoco/jacocoMerged.exec")
|
|
|
|
|
2021-05-06 20:17:04 +02:00
|
|
|
def merge = tasks.register('jacocoMergeReports', JacocoMerge) {
|
2017-08-09 21:56:20 +02:00
|
|
|
group = "Reporting"
|
|
|
|
description = "Merge all jacoco reports from projects into one."
|
|
|
|
|
2018-10-07 20:45:20 +02:00
|
|
|
ListProperty<File> jacocoFiles = project.objects.listProperty(File.class)
|
2018-09-11 22:21:55 +02:00
|
|
|
project.subprojects { subproject ->
|
2018-10-07 20:45:20 +02:00
|
|
|
subproject.plugins.withId("jacoco") {
|
|
|
|
project.logger.info("${subproject.name} has Jacoco plugin applied")
|
|
|
|
subproject.tasks.withType(Test) { task ->
|
|
|
|
File destFile = task.extensions.getByType(JacocoTaskExtension.class).destinationFile
|
|
|
|
if (destFile.exists() && !task.name.contains("Release")) {
|
|
|
|
jacocoFiles.add(destFile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-11 22:21:55 +02:00
|
|
|
}
|
2017-08-09 21:56:20 +02:00
|
|
|
|
2018-10-07 20:45:20 +02:00
|
|
|
executionData(jacocoFiles)
|
|
|
|
destinationFile(mergedJacocoExec)
|
|
|
|
}
|
2017-08-09 21:56:20 +02:00
|
|
|
|
2021-05-06 20:17:04 +02:00
|
|
|
tasks.register('jacocoFullReport', JacocoReport) {
|
|
|
|
dependsOn merge
|
2018-10-07 20:45:20 +02:00
|
|
|
group = "Reporting"
|
|
|
|
description = "Generate full Jacoco coverage report including all modules."
|
2018-09-11 22:21:55 +02:00
|
|
|
|
2020-06-13 19:04:31 +02:00
|
|
|
getClassDirectories().setFrom(files())
|
|
|
|
getSourceDirectories().setFrom(files())
|
|
|
|
getExecutionData().setFrom(files())
|
2017-08-09 21:56:20 +02:00
|
|
|
|
2018-10-07 20:45:20 +02:00
|
|
|
reports {
|
|
|
|
xml.enabled = true
|
|
|
|
html.enabled = true
|
|
|
|
csv.enabled = false
|
2017-08-09 21:56:20 +02:00
|
|
|
}
|
|
|
|
|
2018-10-07 20:45:20 +02:00
|
|
|
// Always run merging, as all input calculation is done in doFirst {}
|
|
|
|
outputs.upToDateWhen { false }
|
|
|
|
// Task will run anyway even if initial inputs are empty
|
|
|
|
onlyIf = { true }
|
|
|
|
|
2021-05-06 20:17:04 +02:00
|
|
|
project.subprojects { subproject ->
|
|
|
|
subproject.plugins.withId("jacoco") {
|
|
|
|
project.logger.info("${subproject.name} has Jacoco plugin applied")
|
|
|
|
subproject.plugins.withId("kotlin-android") {
|
|
|
|
project.logger.info("${subproject.name} is android project")
|
|
|
|
def mainSources = subproject.extensions.findByName("android").sourceSets['main']
|
|
|
|
project.logger.info("Android sources: ${mainSources.java.srcDirs}")
|
|
|
|
mainSources.java.srcDirs.forEach {
|
|
|
|
additionalSourceDirs(it)
|
2018-10-07 20:45:20 +02:00
|
|
|
}
|
2021-05-06 20:17:04 +02:00
|
|
|
project.logger.info("Subproject exclude: ${subproject.jacocoExclude}")
|
|
|
|
additionalClassDirs(fileTree(
|
|
|
|
dir: "${subproject.buildDir}/tmp/kotlin-classes/debug",
|
|
|
|
excludes: subproject.jacocoExclude
|
|
|
|
))
|
|
|
|
}
|
|
|
|
subproject.plugins.withId("kotlin") { plugin ->
|
|
|
|
project.logger.info("${subproject.name} is common kotlin project")
|
|
|
|
SourceDirectorySet mainSources = subproject.extensions.getByName("kotlin")
|
|
|
|
.sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]
|
|
|
|
.kotlin
|
|
|
|
mainSources.srcDirs.forEach {
|
|
|
|
project.logger.debug("Adding sources: $it")
|
|
|
|
additionalSourceDirs(it)
|
2018-10-07 20:45:20 +02:00
|
|
|
}
|
2021-05-06 20:17:04 +02:00
|
|
|
project.logger.info("Subproject exclude: ${subproject.jacocoExclude}")
|
|
|
|
additionalClassDirs(fileTree(
|
|
|
|
dir: "${subproject.buildDir}/classes/kotlin/main",
|
|
|
|
excludes: subproject.jacocoExclude
|
|
|
|
))
|
|
|
|
}
|
2018-10-07 20:45:20 +02:00
|
|
|
|
2021-05-06 20:17:04 +02:00
|
|
|
subproject.tasks.withType(Test) { task ->
|
|
|
|
File destFile = task.extensions.getByType(JacocoTaskExtension.class).destinationFile
|
|
|
|
if (destFile.exists() && !task.name.contains("Release")) {
|
|
|
|
project.logger.info("Adding execution data: $destFile")
|
|
|
|
executionData(destFile)
|
2018-10-07 20:45:20 +02:00
|
|
|
}
|
2017-08-09 21:56:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-06 20:17:04 +02:00
|
|
|
|
2018-10-07 20:45:20 +02:00
|
|
|
}
|