From f4628b5a499ca0255d30739d5bd4ba67f7efd764 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Thu, 16 Sep 2021 22:29:25 +0200 Subject: [PATCH] Add jacoco implementation --- .gitignore | 4 +++- api/build.gradle | 1 + app/build.gradle | 1 + build.gradle | 57 +++++++++++++++++++++++++++++++++++++++++++++-- db/build.gradle | 9 ++++++++ gradle.properties | 1 - 6 files changed, 69 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b16310a6..4f0565bd 100644 --- a/.gitignore +++ b/.gitignore @@ -132,4 +132,6 @@ fastlane/Fastfile Gemfile -mapping/ \ No newline at end of file +mapping/ + +**/*.exec diff --git a/api/build.gradle b/api/build.gradle index d13bb3e2..9fb1a990 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -28,6 +28,7 @@ android { debug { minifyEnabled false + testCoverageEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } diff --git a/app/build.gradle b/app/build.gradle index 3ddce5c7..ca326bec 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,6 +33,7 @@ android { minifyEnabled false shrinkResources false + testCoverageEnabled true applicationIdSuffix ".debug" proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } diff --git a/build.gradle b/build.gradle index 70d196b9..60d89b91 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.4.32' + ext.kotlin_version = '1.5.30' repositories { google() @@ -10,10 +10,13 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jacoco:org.jacoco.core:0.8.7" } } allprojects { + apply plugin: 'jacoco' + repositories { google() mavenCentral() @@ -35,4 +38,54 @@ ext { task clean(type: Delete) { delete rootProject.buildDir -} \ No newline at end of file +} + +jacoco { + toolVersion = "0.8.7" +} + + +task jacocoFullReport(type: JacocoReport) { + group = 'Reporting' + description = "Generate Jacoco coverage reports for the debug build" + + reports { + html { + enabled true + destination file('build/reports/jacoco/html') + } + xml { + enabled true + destination file('build/reports/jacoco/jacocoFullReport.xml') + } + } + + dependsOn ":app:testDebugUnitTest" + dependsOn ":api:testDebugUnitTest" + dependsOn ":db:testDebugUnitTest" + dependsOn ":app:connectedAndroidTest" + + final fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', 'android/**/*.*'] + + classDirectories.setFrom files([ + fileTree(dir: "$project.rootDir/app/build/intermediates/javac/debug", excludes: fileFilter), + fileTree(dir: "$project.rootDir/app/build/tmp/kotlin-classes/debug", excludes: fileFilter), + fileTree(dir: "$project.rootDir/api/build/intermediates/javac/debug", excludes: fileFilter), + fileTree(dir: "$project.rootDir/api/build/tmp/kotlin-classes/debug", excludes: fileFilter), + fileTree(dir: "$project.rootDir/db/build/tmp/kotlin-classes/debug", excludes: fileFilter), + ]) + def coverageSourceDirs = [ + "$project.rootDir/app/src/main/java", + "$project.rootDir/api/src/main/java", + "$project.rootDir/db/src/main/java", + ] + + additionalSourceDirs.setFrom files(coverageSourceDirs) + sourceDirectories.setFrom files(coverageSourceDirs) + executionData.setFrom fileTree(dir: project.rootDir, includes: [ + 'app/jacoco.exec', + 'db/jacoco.exec', + 'api/jacoco.exec', + 'app/build/outputs/code_coverage/debugAndroidTest/connected/*-coverage.ec' + ]) +} diff --git a/db/build.gradle b/db/build.gradle index 4f0226a9..7f1c8085 100644 --- a/db/build.gradle +++ b/db/build.gradle @@ -40,6 +40,7 @@ android { debug { minifyEnabled false + testCoverageEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } @@ -53,6 +54,14 @@ android { } } +// Needed for kapt starting with kotlin plugin 1.5 +kapt { + arguments { + arg("room.schemaLocation", "$projectDir/schemas".toString()) + arg("room.incremental", "true") + } +} + dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) diff --git a/gradle.properties b/gradle.properties index 70ede94b..7363cef4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,6 @@ org.gradle.jvmargs=-Xmx1536m android.databinding.incremental=true kapt.incremental.apt=true org.gradle.parallel=true -kotlin.parallel.tasks.in.project=true android.defaults.buildfeatures.buildconfig=false