Skip to content

Commit

Permalink
chore: Add Kover plugin (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcreaser authored Jul 24, 2023
1 parent 756d7c4 commit 8ea0a16
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions build-logic/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -57,5 +58,9 @@ gradlePlugin {
id = "amplify.android.ui.component"
implementationClass = "ComponentConventionPlugin"
}
register("kover") {
id = "amplify.android.kover"
implementationClass = "KoverConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +32,7 @@ class ComponentConventionPlugin : Plugin<Project> {
pluginManager.apply("amplify.android.library")
pluginManager.apply("amplify.android.publishing")
pluginManager.apply("amplify.android.dokka")
pluginManager.apply("amplify.android.kover")

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
Expand Down
37 changes: 37 additions & 0 deletions build-logic/plugins/src/main/kotlin/KoverConventionPlugin.kt
Original file line number Diff line number Diff line change
@@ -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<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("org.jetbrains.kotlinx.kover")

extensions.configure<KoverReportExtension> {
defaults {
// Use the release variant for the default coverage report
mergeWith("release")
}
}
}
}
}
10 changes: 8 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}

Expand All @@ -28,3 +28,9 @@ tasks.withType<DokkaTask>().configureEach {
tasks.register<Delete>("clean").configure {
delete(rootProject.buildDir)
}

dependencies {
// Generate combined coverage report
kover(project(":authenticator"))
kover(project(":liveness"))
}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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]
Expand All @@ -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" }

0 comments on commit 8ea0a16

Please sign in to comment.