Skip to content

Commit 8ea0a16

Browse files
authored
chore: Add Kover plugin (#64)
1 parent 756d7c4 commit 8ea0a16

File tree

7 files changed

+58
-7
lines changed

7 files changed

+58
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Amplify UI for Android is an open-source UI library with cloud-connected compone
2929

3030
- https://ui.docs.amplify.aws/android/getting-started/installation
3131

32+
## Generating Code Coverage
33+
34+
A merged code coverage report can be generated by running `./gradlew koverHtmlReport`. Coverage for individual components can be checked using `./gradlew :authenticator:koverHtmlReport`.
35+
3236
## Contributing
3337

3438
- [CONTRIBUTING.md](/CONTRIBUTING.md)

build-logic/plugins/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies {
3232
compileOnly(libs.plugin.android.gradle)
3333
compileOnly(libs.plugin.kotlin.android)
3434
compileOnly(libs.plugin.dokka)
35+
compileOnly(libs.plugin.kover)
3536
compileOnly(libs.plugin.ktlint)
3637
}
3738

@@ -57,5 +58,9 @@ gradlePlugin {
5758
id = "amplify.android.ui.component"
5859
implementationClass = "ComponentConventionPlugin"
5960
}
61+
register("kover") {
62+
id = "amplify.android.kover"
63+
implementationClass = "KoverConventionPlugin"
64+
}
6065
}
6166
}

build-logic/plugins/src/main/kotlin/AndroidLibraryConventionPlugin.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@ import org.gradle.api.tasks.compile.JavaCompile
2121
import org.gradle.api.tasks.testing.Test
2222
import org.gradle.kotlin.dsl.configure
2323
import org.gradle.kotlin.dsl.extra
24-
import org.gradle.kotlin.dsl.gradleKotlinDsl
2524
import org.gradle.kotlin.dsl.provideDelegate
2625
import org.gradle.kotlin.dsl.withType
27-
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
2826
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2927

30-
31-
3228
/**
3329
* This convention plugin configures an Android library module
3430
*/

build-logic/plugins/src/main/kotlin/ComponentConventionPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
import org.gradle.api.JavaVersion
1716
import org.gradle.api.Plugin
1817
import org.gradle.api.Project
1918
import org.gradle.kotlin.dsl.withType
@@ -33,6 +32,7 @@ class ComponentConventionPlugin : Plugin<Project> {
3332
pluginManager.apply("amplify.android.library")
3433
pluginManager.apply("amplify.android.publishing")
3534
pluginManager.apply("amplify.android.dokka")
35+
pluginManager.apply("amplify.android.kover")
3636

3737
tasks.withType<KotlinCompile>().configureEach {
3838
kotlinOptions {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
import kotlinx.kover.gradle.plugin.dsl.KoverReportExtension
17+
import org.gradle.api.Plugin
18+
import org.gradle.api.Project
19+
import org.gradle.kotlin.dsl.configure
20+
21+
/**
22+
* Applies and configures the Kover plugin
23+
*/
24+
class KoverConventionPlugin : Plugin<Project> {
25+
override fun apply(target: Project) {
26+
with(target) {
27+
pluginManager.apply("org.jetbrains.kotlinx.kover")
28+
29+
extensions.configure<KoverReportExtension> {
30+
defaults {
31+
// Use the release variant for the default coverage report
32+
mergeWith("release")
33+
}
34+
}
35+
}
36+
}
37+
}

build.gradle.kts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
import org.jetbrains.dokka.gradle.DokkaTask
4-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
54

65
buildscript {
76
repositories {
@@ -15,9 +14,10 @@ buildscript {
1514
plugins {
1615
alias(libs.plugins.android.application) apply false
1716
alias(libs.plugins.android.library) apply false
17+
alias(libs.plugins.dokka)
1818
alias(libs.plugins.kotlin.android) apply false
1919
alias(libs.plugins.kotlin.serialization) apply false
20-
alias(libs.plugins.dokka)
20+
alias(libs.plugins.kover)
2121
alias(libs.plugins.ktlint) apply false
2222
}
2323

@@ -28,3 +28,9 @@ tasks.withType<DokkaTask>().configureEach {
2828
tasks.register<Delete>("clean").configure {
2929
delete(rootProject.buildDir)
3030
}
31+
32+
dependencies {
33+
// Generate combined coverage report
34+
kover(project(":authenticator"))
35+
kover(project(":liveness"))
36+
}

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dokka = "1.8.10"
77
lifecycle = "2.4.0"
88
kotlin = "1.8.10"
99
ktlint = "11.0.0"
10+
kover = "0.7.2"
1011
material3 = "1.1.0"
1112
paparazzi = "1.2.0"
1213

@@ -49,6 +50,7 @@ test-robolectric = "org.robolectric:robolectric:4.9.2"
4950
plugin-android-gradle = { module = "com.android.tools.build:gradle", version.ref = "agp" }
5051
plugin-kotlin-android = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
5152
plugin-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
53+
plugin-kover = { module = "org.jetbrains.kotlinx:kover-gradle-plugin", version.ref = "kover" }
5254
plugin-ktlint = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" }
5355

5456
[bundles]
@@ -62,5 +64,6 @@ android-library = { id = "com.android.library", version.ref = "agp" }
6264
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
6365
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
6466
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
67+
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
6568
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
6669
paparazzi = { id = "app.cash.paparazzi", version.ref = "paparazzi" }

0 commit comments

Comments
 (0)