diff --git a/README.md b/README.md index 2224b6c6..4ffc6e42 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ Amplify UI for Android is an open-source UI library with cloud-connected compone - https://ui.docs.amplify.aws/android/getting-started/installation +## Generating Code Coverage + +A merged code coverage report can be generated by running `./gradlew koverHtmlReport`. Coverage for individual components can be checked using `./gradlew :authenticator:koverHtmlReport`. + ## Contributing - [CONTRIBUTING.md](/CONTRIBUTING.md) diff --git a/build-logic/plugins/build.gradle.kts b/build-logic/plugins/build.gradle.kts index 9646d4d5..4c9f8005 100644 --- a/build-logic/plugins/build.gradle.kts +++ b/build-logic/plugins/build.gradle.kts @@ -32,6 +32,7 @@ dependencies { compileOnly(libs.plugin.android.gradle) compileOnly(libs.plugin.kotlin.android) compileOnly(libs.plugin.dokka) + compileOnly(libs.plugin.kover) compileOnly(libs.plugin.ktlint) } @@ -57,5 +58,9 @@ gradlePlugin { id = "amplify.android.ui.component" implementationClass = "ComponentConventionPlugin" } + register("kover") { + id = "amplify.android.kover" + implementationClass = "KoverConventionPlugin" + } } } diff --git a/build-logic/plugins/src/main/kotlin/AndroidLibraryConventionPlugin.kt b/build-logic/plugins/src/main/kotlin/AndroidLibraryConventionPlugin.kt index 73ff4dfa..22989256 100644 --- a/build-logic/plugins/src/main/kotlin/AndroidLibraryConventionPlugin.kt +++ b/build-logic/plugins/src/main/kotlin/AndroidLibraryConventionPlugin.kt @@ -21,14 +21,10 @@ import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.testing.Test import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.extra -import org.gradle.kotlin.dsl.gradleKotlinDsl import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - - /** * This convention plugin configures an Android library module */ diff --git a/build-logic/plugins/src/main/kotlin/ComponentConventionPlugin.kt b/build-logic/plugins/src/main/kotlin/ComponentConventionPlugin.kt index 36fd72a9..040f8421 100644 --- a/build-logic/plugins/src/main/kotlin/ComponentConventionPlugin.kt +++ b/build-logic/plugins/src/main/kotlin/ComponentConventionPlugin.kt @@ -13,7 +13,6 @@ * permissions and limitations under the License. */ -import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.withType @@ -33,6 +32,7 @@ class ComponentConventionPlugin : Plugin { pluginManager.apply("amplify.android.library") pluginManager.apply("amplify.android.publishing") pluginManager.apply("amplify.android.dokka") + pluginManager.apply("amplify.android.kover") tasks.withType().configureEach { kotlinOptions { diff --git a/build-logic/plugins/src/main/kotlin/KoverConventionPlugin.kt b/build-logic/plugins/src/main/kotlin/KoverConventionPlugin.kt new file mode 100644 index 00000000..f04ab0e6 --- /dev/null +++ b/build-logic/plugins/src/main/kotlin/KoverConventionPlugin.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +import kotlinx.kover.gradle.plugin.dsl.KoverReportExtension +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure + +/** + * Applies and configures the Kover plugin + */ +class KoverConventionPlugin : Plugin { + override fun apply(target: Project) { + with(target) { + pluginManager.apply("org.jetbrains.kotlinx.kover") + + extensions.configure { + defaults { + // Use the release variant for the default coverage report + mergeWith("release") + } + } + } + } +} diff --git a/build.gradle.kts b/build.gradle.kts index 9b16c6af..bb822902 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. import org.jetbrains.dokka.gradle.DokkaTask -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { repositories { @@ -15,9 +14,10 @@ buildscript { plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.android.library) apply false + alias(libs.plugins.dokka) alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.kotlin.serialization) apply false - alias(libs.plugins.dokka) + alias(libs.plugins.kover) alias(libs.plugins.ktlint) apply false } @@ -28,3 +28,9 @@ tasks.withType().configureEach { tasks.register("clean").configure { delete(rootProject.buildDir) } + +dependencies { + // Generate combined coverage report + kover(project(":authenticator")) + kover(project(":liveness")) +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bfb8e17c..adc256bd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,6 +7,7 @@ dokka = "1.8.10" lifecycle = "2.4.0" kotlin = "1.8.10" ktlint = "11.0.0" +kover = "0.7.2" material3 = "1.1.0" paparazzi = "1.2.0" @@ -49,6 +50,7 @@ test-robolectric = "org.robolectric:robolectric:4.9.2" plugin-android-gradle = { module = "com.android.tools.build:gradle", version.ref = "agp" } plugin-kotlin-android = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } plugin-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" } +plugin-kover = { module = "org.jetbrains.kotlinx:kover-gradle-plugin", version.ref = "kover" } plugin-ktlint = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" } [bundles] @@ -62,5 +64,6 @@ android-library = { id = "com.android.library", version.ref = "agp" } dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" } paparazzi = { id = "app.cash.paparazzi", version.ref = "paparazzi" }