Rework jacoco report generation for android projects.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
2a1dfc3e8d
commit
501015c649
|
@ -12,9 +12,7 @@ buildscript {
|
|||
classpath gradlePlugins.kotlin
|
||||
classpath gradlePlugins.ktlintGradle
|
||||
classpath gradlePlugins.detekt
|
||||
classpath(gradlePlugins.jacocoAndroid) {
|
||||
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
|
||||
}
|
||||
classpath gradlePlugins.jacoco
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ ext.versions = [
|
|||
ktlintGradle : "4.1.0",
|
||||
detekt : "1.0.0.RC6-4",
|
||||
jacoco : "0.8.1",
|
||||
jacocoAndroid : "0.1.3",
|
||||
|
||||
androidSupport : "22.2.1",
|
||||
|
||||
|
@ -37,7 +36,7 @@ ext.gradlePlugins = [
|
|||
kotlin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin",
|
||||
ktlintGradle : "gradle.plugin.org.jlleitschuh.gradle:ktlint-gradle:$versions.ktlintGradle",
|
||||
detekt : "gradle.plugin.io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$versions.detekt",
|
||||
jacocoAndroid : "com.dicedmelon.gradle:jacoco-android:$versions.jacocoAndroid"
|
||||
jacoco : "org.jacoco:org.jacoco.core:$versions.jacoco"
|
||||
]
|
||||
|
||||
ext.androidSupport = [
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
apply plugin: 'jacoco'
|
||||
|
||||
jacoco {
|
||||
toolVersion(versions.jacoco)
|
||||
}
|
||||
|
||||
task jacocoMergeReports(type: JacocoMerge) {
|
||||
group = "Reporting"
|
||||
description = "Merge all jacoco reports from projects into one."
|
||||
|
||||
def subsonicApi = project.findProject("subsonic-api")
|
||||
def ultrasonicApp = project.findProject("ultrasonic")
|
||||
def cache = project.findProject("cache")
|
||||
executionData(
|
||||
"${subsonicApi.buildDir}/jacoco/test.exec",
|
||||
"${ultrasonicApp.buildDir}/jacoco/testDebugUnitTest.exec",
|
||||
"${cache.buildDir}/jacoco/test.exec"
|
||||
)
|
||||
List<File> jacocoFiles = new ArrayList<>()
|
||||
project.subprojects { subproject ->
|
||||
File commonModuleReport = new File(subproject.buildDir, "/jacoco/test.exec")
|
||||
if (commonModuleReport.exists()) jacocoFiles.add(commonModuleReport)
|
||||
File androidModuleReport = new File(subproject.buildDir, "/jacoco/testDebugUnitTest.exec")
|
||||
if (androidModuleReport.exists()) jacocoFiles.add(androidModuleReport)
|
||||
}
|
||||
executionData(jacocoFiles.toArray())
|
||||
destinationFile(file("${project.buildDir}/jacoco/jacoco.exec"))
|
||||
}
|
||||
|
||||
|
@ -20,35 +24,33 @@ def createJacocoFullReportTask() {
|
|||
group = "Reporting"
|
||||
description = "Generate full Jacoco coverage report including all modules."
|
||||
|
||||
def subsonicApi = project.findProject("subsonic-api")
|
||||
def subsonicApiImageLoader = project.findProject("subsonic-api-image-loader")
|
||||
def ultrasonicApp = project.findProject("ultrasonic")
|
||||
def cache = project.findProject("cache")
|
||||
|
||||
classDirectories = files(
|
||||
fileTree(
|
||||
dir: "${subsonicApi.buildDir}/classes/main",
|
||||
excludes: subsonicApi.jacocoExclude
|
||||
),
|
||||
fileTree(
|
||||
dir: "${subsonicApiImageLoader.buildDir}/intermediates/classes/debug/org",
|
||||
excludes: subsonicApiImageLoader.jacocoExclude
|
||||
),
|
||||
fileTree(
|
||||
dir: "${ultrasonicApp.buildDir}/intermediates/classes/debug/org",
|
||||
excludes: ultrasonicApp.jacocoExclude
|
||||
),
|
||||
fileTree(
|
||||
dir: "${cache.buildDir}/classes/kotlin/main",
|
||||
excludes: cache.jacocoExclude
|
||||
List<FileTree> classFileTreeList = new ArrayList<>()
|
||||
List<FileTree> sourceFileTreeList = new ArrayList<>()
|
||||
project.subprojects { subproject ->
|
||||
if (subproject.plugins.hasPlugin("kotlin-android") &&
|
||||
subproject.hasProperty("jacocoExclude")) {
|
||||
classFileTreeList.add(
|
||||
fileTree(
|
||||
dir: "${subproject.buildDir}/tmp/kotlin-classes/debug",
|
||||
excludes: subproject.jacocoExclude
|
||||
)
|
||||
)
|
||||
)
|
||||
sourceDirectories = files(
|
||||
subsonicApi.sourceSets.main.getAllSource(),
|
||||
subsonicApiImageLoader.extensions.getByName('android').sourceSets.main.java.sourceFiles,
|
||||
ultrasonicApp.extensions.getByName('android').sourceSets.main.java.sourceFiles,
|
||||
cache.sourceSets.main.getAllSource(),
|
||||
)
|
||||
sourceFileTreeList.add(
|
||||
subproject.extensions.getByName('android').sourceSets.main.java.sourceFiles
|
||||
)
|
||||
} else if (subproject.hasProperty("jacocoExclude")) {
|
||||
classFileTreeList.add(
|
||||
fileTree(
|
||||
dir: "${subproject.buildDir}/classes/kotlin/main",
|
||||
excludes: subproject.jacocoExclude
|
||||
)
|
||||
)
|
||||
sourceFileTreeList.add(subproject.sourceSets.main.getAllSource())
|
||||
}
|
||||
}
|
||||
|
||||
classDirectories = files(classFileTreeList.toArray())
|
||||
sourceDirectories = files(sourceFileTreeList.toArray())
|
||||
executionData = files("${buildDir}/jacoco/jacoco.exec")
|
||||
|
||||
reports {
|
||||
|
|
|
@ -1,7 +1,20 @@
|
|||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'jacoco-android'
|
||||
apply from: '../gradle_scripts/code_quality.gradle'
|
||||
apply plugin: 'jacoco'
|
||||
|
||||
|
||||
ext {
|
||||
jacocoExclude = []
|
||||
}
|
||||
|
||||
jacoco {
|
||||
toolVersion(versions.jacoco)
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
jacoco.includeNoLocationClasses = true
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion(versions.compileSdk)
|
||||
|
@ -37,19 +50,3 @@ dependencies {
|
|||
testImplementation testing.kluent
|
||||
testImplementation testing.robolectric
|
||||
}
|
||||
|
||||
jacoco {
|
||||
toolVersion(versions.jacoco)
|
||||
}
|
||||
|
||||
ext {
|
||||
jacocoExclude = []
|
||||
}
|
||||
|
||||
jacocoAndroidUnitTestReport {
|
||||
excludes += jacocoExclude
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
testDebugUnitTest.finalizedBy jacocoTestDebugUnitTestReport
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'jacoco-android'
|
||||
apply plugin: 'jacoco'
|
||||
apply from: "../gradle_scripts/code_quality.gradle"
|
||||
|
||||
android {
|
||||
|
@ -90,10 +90,11 @@ ext {
|
|||
'**/di/**'
|
||||
]
|
||||
}
|
||||
jacocoAndroidUnitTestReport {
|
||||
excludes += jacocoExclude
|
||||
|
||||
jacoco {
|
||||
toolVersion(versions.jacoco)
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
testDebugUnitTest.finalizedBy jacocoTestDebugUnitTestReport
|
||||
tasks.withType(Test) {
|
||||
jacoco.includeNoLocationClasses = true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue