From 8124ce4b626596ae7413faf4077ecec9286991d8 Mon Sep 17 00:00:00 2001 From: Sergey Shanshin Date: Tue, 9 May 2023 17:55:54 +0300 Subject: [PATCH] Upgraded Kover version to 0.7.0-Beta (#3734) Co-authored-by: Vsevolod Tolstopyatov --- build.gradle | 2 +- buildSrc/build.gradle.kts | 2 +- .../main/kotlin/kover-conventions.gradle.kts | 70 +++++++++++++------ gradle.properties | 2 +- kotlinx-coroutines-core/build.gradle | 26 +++++-- kotlinx-coroutines-debug/build.gradle | 20 +++--- .../build.gradle.kts | 23 +++--- .../build.gradle.kts | 18 +++-- .../build.gradle.kts | 6 -- 9 files changed, 107 insertions(+), 62 deletions(-) diff --git a/build.gradle b/build.gradle index 0d17d9dd7b..84d777018e 100644 --- a/build.gradle +++ b/build.gradle @@ -66,8 +66,8 @@ buildscript { classpath "com.github.node-gradle:gradle-node-plugin:$gradle_node_version" classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version" classpath "ru.vyarus:gradle-animalsniffer-plugin:1.5.4" // Android API check - classpath "org.jetbrains.kotlinx:kover:$kover_version" classpath "org.jetbrains.kotlin:atomicfu:$kotlin_version" + classpath "org.jetbrains.kotlinx:kover-gradle-plugin:$kover_version" // JMH plugins classpath "gradle.plugin.com.github.johnrengelman:shadow:7.1.2" diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 785d13fdbc..c37ac64d0b 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -62,7 +62,7 @@ dependencies { exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib") } implementation("ru.vyarus:gradle-animalsniffer-plugin:1.5.3") // Android API check - implementation("org.jetbrains.kotlinx:kover:${version("kover")}") { + implementation("org.jetbrains.kotlinx:kover-gradle-plugin:${version("kover")}") { exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8") exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7") exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib") diff --git a/buildSrc/src/main/kotlin/kover-conventions.gradle.kts b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts index c177c638d3..7a0a62f5ae 100644 --- a/buildSrc/src/main/kotlin/kover-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts @@ -1,9 +1,11 @@ -import kotlinx.kover.api.* -import kotlinx.kover.tasks.* +import kotlinx.kover.gradle.plugin.dsl.* /* * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ +plugins { + id("org.jetbrains.kotlinx.kover") +} val notCovered = sourceless + internal + unpublished @@ -16,38 +18,60 @@ val expectedCoverage = mutableMapOf( "kotlinx-coroutines-reactor" to 75 ) +val conventionProject = project + subprojects { val projectName = name if (projectName in notCovered) return@subprojects - apply(plugin = "kover") - extensions.configure { + project.apply(plugin = "org.jetbrains.kotlinx.kover") + conventionProject.dependencies.add("kover", this) + + extensions.configure("kover") { /* - * Is explicitly enabled on TC in a separate build step. - * Examples: - * ./gradlew :p:check -- doesn't verify coverage - * ./gradlew :p:check -Pkover.enabled=true -- verifies coverage - * ./gradlew :p:koverReport -Pkover.enabled=true -- generates report - */ - isDisabled.set(!(properties["kover.enabled"]?.toString()?.toBoolean() ?: false)) + * Is explicitly enabled on TC in a separate build step. + * Examples: + * ./gradlew :p:check -- doesn't verify coverage + * ./gradlew :p:check -Pkover.enabled=true -- verifies coverage + * ./gradlew :p:koverHtmlReport -Pkover.enabled=true -- generates HTML report + */ + if (properties["kover.enabled"]?.toString()?.toBoolean() != true) { + disable() + } + } - verify { - rule { - bound { + extensions.configure("koverReport") { + defaults { + html { + setReportDir(conventionProject.layout.buildDirectory.dir("kover/${project.name}/html")) + } + + verify { + rule { /* - * 85 is our baseline that we aim to raise to 90+. - * Missing coverage is typically due to bugs in the agent - * (e.g. signatures deprecated with an error are counted), - * sometimes it's various diagnostic `toString` or `catch` for OOMs/VerificationErrors, - * but some places are definitely worth visiting. - */ - minValue = expectedCoverage[projectName] ?: 85 // COVERED_LINES_PERCENTAGE + * 85 is our baseline that we aim to raise to 90+. + * Missing coverage is typically due to bugs in the agent + * (e.g. signatures deprecated with an error are counted), + * sometimes it's various diagnostic `toString` or `catch` for OOMs/VerificationErrors, + * but some places are definitely worth visiting. + */ + minBound(expectedCoverage[projectName] ?: 85) // COVERED_LINES_PERCENTAGE } } } + } +} - htmlReport { - reportDir.set(file(rootProject.buildDir.toString() + "/kover/" + project.name + "/html")) +koverReport { + defaults { + verify { + rule { + minBound(85) // COVERED_LINES_PERCENTAGE + } } } } + +conventionProject.tasks.register("koverReport") { + dependsOn(conventionProject.tasks.named("koverHtmlReport")) +} diff --git a/gradle.properties b/gradle.properties index 2daed3cf4c..11d347bc2c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ rxjava3_version=3.0.2 javafx_version=17.0.2 javafx_plugin_version=0.0.8 binary_compatibility_validator_version=0.12.0 -kover_version=0.6.1 +kover_version=0.7.0-Beta blockhound_version=1.0.2.RELEASE jna_version=5.9.0 diff --git a/kotlinx-coroutines-core/build.gradle b/kotlinx-coroutines-core/build.gradle index 7693966a46..1b1d4a4cb2 100644 --- a/kotlinx-coroutines-core/build.gradle +++ b/kotlinx-coroutines-core/build.gradle @@ -4,6 +4,10 @@ apply plugin: 'org.jetbrains.kotlin.multiplatform' apply plugin: 'org.jetbrains.dokka' + +// apply plugin to use autocomplete for Kover DSL +apply plugin: 'org.jetbrains.kotlinx.kover' + apply from: rootProject.file("gradle/compile-jvm-multiplatform.gradle") apply from: rootProject.file("gradle/compile-common.gradle") @@ -320,12 +324,26 @@ def commonKoverExcludes = ] kover { - instrumentation { - excludeTasks.add("jvmLincheckTest") // Always disabled, lincheck doesn't really support coverage + excludeTests { + // Always disabled, lincheck doesn't really support coverage + tasks("jvmLincheckTest") + } + + excludeInstrumentation { + // lincheck has NPE error on `ManagedStrategyStateHolder` class + classes("org.jetbrains.kotlinx.lincheck.*") } +} + +koverReport { filters { - classes { - excludes.addAll(commonKoverExcludes) + excludes { + classes( + "kotlinx.coroutines.debug.*", // Tested by debug module + "kotlinx.coroutines.channels.ChannelsKt__DeprecatedKt.*", // Deprecated + "kotlinx.coroutines.scheduling.LimitingDispatcher", // Deprecated + "kotlinx.coroutines.scheduling.ExperimentalCoroutineDispatcher" // Deprecated + ) } } } diff --git a/kotlinx-coroutines-debug/build.gradle b/kotlinx-coroutines-debug/build.gradle index ded13b7b5a..340c1d21dc 100644 --- a/kotlinx-coroutines-debug/build.gradle +++ b/kotlinx-coroutines-debug/build.gradle @@ -4,6 +4,9 @@ apply plugin: "com.github.johnrengelman.shadow" +// apply plugin to use autocomplete for Kover DSL +apply plugin: 'org.jetbrains.kotlinx.kover' + configurations { shadowDeps // shaded dependencies, not included into the resulting .pom file compileOnly.extendsFrom(shadowDeps) @@ -53,14 +56,11 @@ configurations { } } -def commonKoverExcludes = - // Never used, safety mechanism - ["kotlinx.coroutines.debug.internal.NoOpProbesKt"] - -tasks.koverHtmlReport { - excludes = commonKoverExcludes -} - -tasks.koverVerify { - excludes = commonKoverExcludes +koverReport { + filters { + excludes { + // Never used, safety mechanism + classes("kotlinx.coroutines.debug.internal.NoOpProbesKt") + } + } } diff --git a/reactive/kotlinx-coroutines-reactive/build.gradle.kts b/reactive/kotlinx-coroutines-reactive/build.gradle.kts index 3f2ba6b829..fbcde96527 100644 --- a/reactive/kotlinx-coroutines-reactive/build.gradle.kts +++ b/reactive/kotlinx-coroutines-reactive/build.gradle.kts @@ -1,7 +1,14 @@ +import kotlinx.kover.gradle.plugin.dsl.* + /* * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ +plugins { + // apply plugin to use autocomplete for Kover DSL + id("org.jetbrains.kotlinx.kover") +} + val reactiveStreamsVersion = property("reactive_streams_version") dependencies { @@ -35,16 +42,14 @@ externalDocumentationLink( url = "https://www.reactive-streams.org/reactive-streams-$reactiveStreamsVersion-javadoc/" ) -val commonKoverExcludes = listOf( - "kotlinx.coroutines.reactive.FlowKt", // Deprecated - "kotlinx.coroutines.reactive.FlowKt__MigrationKt", // Deprecated - "kotlinx.coroutines.reactive.ConvertKt" // Deprecated -) - -kover { +koverReport { filters { - classes { - excludes += commonKoverExcludes + excludes { + classes( + "kotlinx.coroutines.reactive.FlowKt", // Deprecated + "kotlinx.coroutines.reactive.FlowKt__MigrationKt", // Deprecated + "kotlinx.coroutines.reactive.ConvertKt" // Deprecated + ) } } } diff --git a/reactive/kotlinx-coroutines-reactor/build.gradle.kts b/reactive/kotlinx-coroutines-reactor/build.gradle.kts index a90b3cbd3c..7d3441ca00 100644 --- a/reactive/kotlinx-coroutines-reactor/build.gradle.kts +++ b/reactive/kotlinx-coroutines-reactor/build.gradle.kts @@ -2,6 +2,11 @@ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ +plugins { + // apply plugin to use autocomplete for Kover DSL + id("org.jetbrains.kotlinx.kover") +} + val reactorVersion = version("reactor") dependencies { @@ -28,15 +33,14 @@ externalDocumentationLink( url = "https://projectreactor.io/docs/core/$reactorVersion/api/" ) -val commonKoverExcludes = listOf( - "kotlinx.coroutines.reactor.FlowKt", // Deprecated - "kotlinx.coroutines.reactor.ConvertKt\$asFlux$1" // Deprecated -) -kover { +koverReport { filters { - classes { - excludes += commonKoverExcludes + excludes { + classes( + "kotlinx.coroutines.reactor.FlowKt", // Deprecated + "kotlinx.coroutines.reactor.ConvertKt\$asFlux$1" // Deprecated + ) } } } diff --git a/ui/kotlinx-coroutines-android/build.gradle.kts b/ui/kotlinx-coroutines-android/build.gradle.kts index b5c9c0cf5d..70bc61582b 100644 --- a/ui/kotlinx-coroutines-android/build.gradle.kts +++ b/ui/kotlinx-coroutines-android/build.gradle.kts @@ -112,9 +112,3 @@ open class RunR8 : JavaExec() { super.exec() } } - -tasks.withType { - extensions.configure { - excludes.addAll(listOf("com.android.*", "android.*")) // Exclude robolectric-generated classes - } -}