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