From 3f6745d6d671a07dca63532a0a5ac90173f722a6 Mon Sep 17 00:00:00 2001 From: Sergey Shanshin Date: Wed, 8 Jan 2025 15:26:02 +0300 Subject: [PATCH] Added ability to specify inclusion filter for source sets Resolves #714 PR #726 --- .../api/kover-gradle-plugin.api | 1 + kover-gradle-plugin/docs/index.md | 33 ++++- .../test/functional/cases/SourceSetsTests.kt | 131 ++++++++++++++++++ .../functional/framework/checker/Checker.kt | 4 + .../framework/checker/CheckerTypes.kt | 2 + .../framework/runner/BuildsRunner.kt | 18 +++ .../functional/framework/starter/Commons.kt | 15 ++ .../builds/sourcesets-multi/build.gradle.kts | 11 ++ .../sourcesets-multi/settings.gradle.kts | 8 ++ .../src/extra/kotlin/ExtraClass.kt | 7 + .../src/foo/kotlin/FooClass.kt | 7 + .../src/main/kotlin/MainClass.kt | 7 + .../src/test/kotlin/TestClasses.kt | 10 ++ .../gradle/plugin/appliers/KoverMerge.kt | 1 + .../appliers/artifacts/JvmVariantArtifacts.kt | 21 ++- .../gradle/plugin/dsl/KoverVariantConfig.kt | 20 ++- .../plugin/dsl/internal/VariantsImpl.kt | 2 + 17 files changed, 292 insertions(+), 6 deletions(-) create mode 100644 kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/SourceSetsTests.kt create mode 100644 kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/build.gradle.kts create mode 100644 kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/settings.gradle.kts create mode 100644 kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/extra/kotlin/ExtraClass.kt create mode 100644 kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/foo/kotlin/FooClass.kt create mode 100644 kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/main/kotlin/MainClass.kt create mode 100644 kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/test/kotlin/TestClasses.kt diff --git a/kover-gradle-plugin/api/kover-gradle-plugin.api b/kover-gradle-plugin/api/kover-gradle-plugin.api index 16200fae..dfd47f1d 100644 --- a/kover-gradle-plugin/api/kover-gradle-plugin.api +++ b/kover-gradle-plugin/api/kover-gradle-plugin.api @@ -295,6 +295,7 @@ public abstract interface class kotlinx/kover/gradle/plugin/dsl/KoverVariantCrea public abstract interface class kotlinx/kover/gradle/plugin/dsl/KoverVariantSources { public abstract fun getExcludeJava ()Lorg/gradle/api/provider/Property; public abstract fun getExcludedSourceSets ()Lorg/gradle/api/provider/SetProperty; + public abstract fun getIncludedSourceSets ()Lorg/gradle/api/provider/SetProperty; } public abstract interface class kotlinx/kover/gradle/plugin/dsl/KoverVerificationRulesConfig { diff --git a/kover-gradle-plugin/docs/index.md b/kover-gradle-plugin/docs/index.md index e6a9b621..9437c5ef 100644 --- a/kover-gradle-plugin/docs/index.md +++ b/kover-gradle-plugin/docs/index.md @@ -1120,9 +1120,9 @@ By specifying an empty filter `filters { }`, you can completely disable report f ### Exclusion of JVM source sets -It is possible to exclude from all reports the code declared in certain source sets. +Code declarations from `test` source set are excluded by default. -As a side effect, the generation of Kover reports ceases to depend on the compilation tasks of these source sets. +It is possible to exclude from all reports the code declared in certain source sets. ```kotlin kover { @@ -1134,6 +1134,35 @@ kover { } ``` +In addition, it is possible to exclude classes from all source sets that are not specified. + +```kotlin +kover { + currentProject { + sources { + includedSourceSets.addAll("main") + } + } +} +``` + +This way, only classes from the `main` source set will be included in the report, but not from others. + +These filters can be combined, the `excludedSourceSets` filter has priority. +```kotlin +kover { + currentProject { + sources { + includedSourceSets.addAll("main", "extra") + excludedSourceSets.addAll("main") + } + } +} +``` +In this case, only classes from the `extra` source set will be included in the report. + +As a side effect of the source set exclusion, the generation of Kover reports ceases to depend on the compilation tasks of excluded source sets. + ### Exclusion of test tasks If some task does not test the coverage of application classes, or it is necessary to exclude its coverage from reports, then specify this task in the excluded list. diff --git a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/SourceSetsTests.kt b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/SourceSetsTests.kt new file mode 100644 index 00000000..ff604b1b --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/SourceSetsTests.kt @@ -0,0 +1,131 @@ +/* + * Copyright 2017-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +package kotlinx.kover.gradle.plugin.test.functional.cases + +import kotlinx.kover.gradle.plugin.test.functional.framework.checker.createCheckerContext +import kotlinx.kover.gradle.plugin.test.functional.framework.runner.buildFromTemplate +import kotlinx.kover.gradle.plugin.test.functional.framework.runner.runWithParams +import org.junit.jupiter.api.Test +import kotlin.test.assertTrue + +internal class SourceSetsTests { + + @Test + fun testExclude() { + val template = buildFromTemplate("sourcesets-multi") + + template.kover { + currentProject { + sources.excludedSourceSets.addAll("main", "foo") + } + } + + val gradleBuild = template.generate() + val buildResult = gradleBuild.runWithParams(":koverXmlReport") + + gradleBuild.createCheckerContext(buildResult).xmlReport { + assertTrue(buildResult.isSuccessful, "Build should be successful") + classCounter("kotlinx.kover.examples.sourcesets.MainClass").assertAbsent() + classCounter("kotlinx.kover.examples.sourcesets.FooClass").assertAbsent() + classCounter("kotlinx.kover.examples.sourcesets.ExtraClass").assertPresent() + classCounter("kotlinx.kover.examples.sourcesets.TestClasses").assertAbsent() + } + } + + @Test + fun testInclude() { + val template = buildFromTemplate("sourcesets-multi") + + template.kover { + currentProject { + sources.includedSourceSets.addAll("extra") + } + } + + val gradleBuild = template.generate() + val buildResult = gradleBuild.runWithParams(":koverXmlReport") + + gradleBuild.createCheckerContext(buildResult).xmlReport { + assertTrue(buildResult.isSuccessful, "Build should be successful") + classCounter("kotlinx.kover.examples.sourcesets.MainClass").assertAbsent() + classCounter("kotlinx.kover.examples.sourcesets.FooClass").assertAbsent() + classCounter("kotlinx.kover.examples.sourcesets.ExtraClass").assertPresent() + classCounter("kotlinx.kover.examples.sourcesets.TestClasses").assertAbsent() + } + } + + @Test + fun testInclude2() { + val template = buildFromTemplate("sourcesets-multi") + + template.kover { + currentProject { + sources.includedSourceSets.addAll("extra", "foo") + } + } + + val gradleBuild = template.generate() + val buildResult = gradleBuild.runWithParams(":koverXmlReport") + + gradleBuild.createCheckerContext(buildResult).xmlReport { + assertTrue(buildResult.isSuccessful, "Build should be successful") + classCounter("kotlinx.kover.examples.sourcesets.MainClass").assertAbsent() + classCounter("kotlinx.kover.examples.sourcesets.FooClass").assertPresent() + classCounter("kotlinx.kover.examples.sourcesets.ExtraClass").assertPresent() + classCounter("kotlinx.kover.examples.sourcesets.TestClasses").assertAbsent() + } + } + + @Test + fun testMixed() { + val template = buildFromTemplate("sourcesets-multi") + + template.kover { + currentProject { + sources { + includedSourceSets.addAll("extra", "foo") + excludedSourceSets.add("foo") + } + } + } + + val gradleBuild = template.generate() + val buildResult = gradleBuild.runWithParams(":koverXmlReport") + + gradleBuild.createCheckerContext(buildResult).xmlReport { + assertTrue(buildResult.isSuccessful, "Build should be successful") + classCounter("kotlinx.kover.examples.sourcesets.MainClass").assertAbsent() + classCounter("kotlinx.kover.examples.sourcesets.FooClass").assertAbsent() + classCounter("kotlinx.kover.examples.sourcesets.ExtraClass").assertPresent() + classCounter("kotlinx.kover.examples.sourcesets.TestClasses").assertAbsent() + } + } + + @Test + fun testTestSourceSet() { + val template = buildFromTemplate("sourcesets-multi") + + template.kover { + currentProject { + sources { + includedSourceSets.addAll("test") + } + } + } + + val gradleBuild = template.generate() + val buildResult = gradleBuild.runWithParams(":koverXmlReport") + + gradleBuild.createCheckerContext(buildResult).xmlReport { + assertTrue(buildResult.isSuccessful, "Build should be successful") + classCounter("kotlinx.kover.examples.sourcesets.MainClass").assertAbsent() + classCounter("kotlinx.kover.examples.sourcesets.FooClass").assertAbsent() + classCounter("kotlinx.kover.examples.sourcesets.ExtraClass").assertAbsent() + classCounter("kotlinx.kover.examples.sourcesets.TestClasses").assertPresent() + } + } + + +} \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/checker/Checker.kt b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/checker/Checker.kt index d24af708..a1bbc65d 100644 --- a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/checker/Checker.kt +++ b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/checker/Checker.kt @@ -460,6 +460,10 @@ private class CounterImpl( assertNull(values, "Counter '$symbol' with type '$type' isn't absent") } + override fun assertPresent() { + assertNotNull(values, "Counter for '$symbol' with type '$type' isn't present in report") + } + override fun assertFullyMissed() { assertNotNull(values, "Counter '$symbol' with type '$type' isn't fully missed because it absent") assertTrue(values.missed > 0, "Counter '$symbol' with type '$type' isn't fully missed") diff --git a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/checker/CheckerTypes.kt b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/checker/CheckerTypes.kt index fdec1ce8..4cfd0273 100644 --- a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/checker/CheckerTypes.kt +++ b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/checker/CheckerTypes.kt @@ -73,6 +73,8 @@ internal interface ProjectAnalysisData { internal interface Counter { fun assertAbsent() + fun assertPresent() + fun assertFullyMissed() fun assertCovered() diff --git a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/runner/BuildsRunner.kt b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/runner/BuildsRunner.kt index eadcc2ed..9659489c 100644 --- a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/runner/BuildsRunner.kt +++ b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/runner/BuildsRunner.kt @@ -4,9 +4,14 @@ package kotlinx.kover.gradle.plugin.test.functional.framework.runner +import kotlinx.kover.gradle.plugin.dsl.KoverProjectExtension +import kotlinx.kover.gradle.plugin.test.functional.framework.common.BuildSlice +import kotlinx.kover.gradle.plugin.test.functional.framework.common.ScriptLanguage import kotlinx.kover.gradle.plugin.test.functional.framework.common.isDebugEnabled import kotlinx.kover.gradle.plugin.test.functional.framework.common.logInfo import kotlinx.kover.gradle.plugin.test.functional.framework.common.uri +import kotlinx.kover.gradle.plugin.test.functional.framework.configurator.ProjectScope +import kotlinx.kover.gradle.plugin.test.functional.framework.mirroring.printGradleDsl import kotlinx.kover.gradle.plugin.test.functional.framework.starter.* import kotlinx.kover.gradle.plugin.test.functional.framework.starter.buildSrc import kotlinx.kover.gradle.plugin.test.functional.framework.starter.patchSettingsFile @@ -31,6 +36,8 @@ internal interface BuildSource { fun from(rootProjectDir: File) + fun kover(config: KoverProjectExtension.(ProjectScope) -> Unit) + fun generate(): GradleBuild } @@ -54,6 +61,8 @@ private class BuildSourceImpl(val snapshotRepos: List, val koverVersion: private var copy: Boolean = false + private val koverBlocks: MutableList<(ScriptLanguage, String) -> String> = mutableListOf() + override var buildName: String = "default" override var buildType: String = "default" @@ -70,6 +79,12 @@ private class BuildSourceImpl(val snapshotRepos: List, val koverVersion: copy = false } + override fun kover(config: KoverProjectExtension.(ProjectScope) -> Unit) { + koverBlocks += { language, gradle -> + printGradleDsl(language, gradle, "kover", config) + } + } + override fun generate(): GradleBuild { val actualDir = dir ?: throw Exception("No source was specified for the build") val targetDir = if (copy) { @@ -88,6 +103,9 @@ private class BuildSourceImpl(val snapshotRepos: List, val koverVersion: val buildSrcScript = targetDir.buildSrc?.build buildSrcScript?.patchKoverDependency(koverVersion) + val buildScript = targetDir.build + buildScript.addKoverBlocks(koverBlocks) + return GradleBuildImpl(targetDir, copy, buildName, buildType) } } diff --git a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/starter/Commons.kt b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/starter/Commons.kt index 6121c68a..0eed54c9 100644 --- a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/starter/Commons.kt +++ b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/starter/Commons.kt @@ -20,6 +20,7 @@ import java.lang.reflect.Method private const val DIR_PARAM = "build-directory" private const val CHECKER_PARAM = "checker-context" +private const val GRADLE_WITH_ASSIGN_OPERATOR_VERSION = "8.12" internal class RunCommand(val buildSource: BuildSource, val gradleArgs: List) @@ -183,3 +184,17 @@ internal fun File.patchKoverDependency(koverVersion: String) { } } } + +internal fun File.addKoverBlocks(koverBlocks: MutableList<(ScriptLanguage, String) -> String>) { + if (koverBlocks.isEmpty()) return + + val language = if (name.endsWith(".kts")) ScriptLanguage.KTS else ScriptLanguage.GROOVY + + val builder = StringBuilder() + koverBlocks.forEach { block -> + builder.appendLine() + builder.append(block(language, GRADLE_WITH_ASSIGN_OPERATOR_VERSION)) + builder.appendLine() + } + appendText(builder.toString()) +} diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/build.gradle.kts b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/build.gradle.kts new file mode 100644 index 00000000..0cbd5265 --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + kotlin("jvm") version "2.1.0" + id("org.jetbrains.kotlinx.kover") version "0.7.0" +} + +sourceSets.create("extra") +sourceSets.create("foo") + +dependencies { + testImplementation(kotlin("test")) +} diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/settings.gradle.kts b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/settings.gradle.kts new file mode 100644 index 00000000..c6dd5abf --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/settings.gradle.kts @@ -0,0 +1,8 @@ +pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + } +} +rootProject.name = "example-source-multi" + diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/extra/kotlin/ExtraClass.kt b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/extra/kotlin/ExtraClass.kt new file mode 100644 index 00000000..8a83a4f4 --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/extra/kotlin/ExtraClass.kt @@ -0,0 +1,7 @@ +package kotlinx.kover.examples.sourcesets + +class ExtraClass { + fun function() { + println("Example") + } +} \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/foo/kotlin/FooClass.kt b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/foo/kotlin/FooClass.kt new file mode 100644 index 00000000..954c014e --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/foo/kotlin/FooClass.kt @@ -0,0 +1,7 @@ +package kotlinx.kover.examples.sourcesets + +class FooClass { + fun function() { + println("Example") + } +} \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/main/kotlin/MainClass.kt b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/main/kotlin/MainClass.kt new file mode 100644 index 00000000..a6b8970c --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/main/kotlin/MainClass.kt @@ -0,0 +1,7 @@ +package kotlinx.kover.examples.sourcesets + +class MainClass { + fun function() { + println("Example") + } +} \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/test/kotlin/TestClasses.kt b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/test/kotlin/TestClasses.kt new file mode 100644 index 00000000..9ecf8522 --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/sourcesets-multi/src/test/kotlin/TestClasses.kt @@ -0,0 +1,10 @@ +package kotlinx.kover.examples.sourcesets + +import kotlin.test.Test + +class TestClasses { + @Test + fun test() { + // no-tests + } +} diff --git a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/KoverMerge.kt b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/KoverMerge.kt index 5110f0a2..68a75e81 100644 --- a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/KoverMerge.kt +++ b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/KoverMerge.kt @@ -97,6 +97,7 @@ private fun KoverVariantSources.wrap(project: Project): KoverMergingVariantSourc return object : KoverMergingVariantSources { override val excludeJava: Property = this@wrap.excludeJava override val excludedSourceSets: SetProperty = this@wrap.excludedSourceSets + override val includedSourceSets: SetProperty = this@wrap.includedSourceSets override val project: Project = project } } diff --git a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/artifacts/JvmVariantArtifacts.kt b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/artifacts/JvmVariantArtifacts.kt index c01e082a..a200e534 100644 --- a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/artifacts/JvmVariantArtifacts.kt +++ b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/artifacts/JvmVariantArtifacts.kt @@ -10,6 +10,7 @@ import kotlinx.kover.gradle.plugin.commons.VariantOriginAttr import kotlinx.kover.gradle.plugin.dsl.internal.KoverVariantConfigImpl import kotlinx.kover.gradle.plugin.appliers.origin.JvmVariantOrigin import kotlinx.kover.gradle.plugin.commons.JVM_VARIANT_NAME +import kotlinx.kover.gradle.plugin.dsl.KoverVariantSources import kotlinx.kover.gradle.plugin.dsl.internal.KoverProjectExtensionImpl import kotlinx.kover.gradle.plugin.tools.CoverageTool import org.gradle.api.Project @@ -48,9 +49,25 @@ internal class JvmVariantArtifacts( } fromOrigin(variantOrigin) { compilationName -> - compilationName !in variantConfig.sources.excludedSourceSets.get() - && compilationName != "test" + !compilationIsExcluded(compilationName, variantConfig.sources) } } + private fun compilationIsExcluded(compilationName: String, variant: KoverVariantSources): Boolean { + if (compilationName in variant.excludedSourceSets.get()) { + return true + } + + val included = variant.includedSourceSets.get() + + if (included.isEmpty() && compilationName == "test") { + return true + } + if (included.isNotEmpty() && compilationName !in included) { + return true + } + + return false + } + } \ No newline at end of file diff --git a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/KoverVariantConfig.kt b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/KoverVariantConfig.kt index dc9fbf0c..7bc36146 100644 --- a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/KoverVariantConfig.kt +++ b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/KoverVariantConfig.kt @@ -6,7 +6,6 @@ package kotlinx.kover.gradle.plugin.dsl import kotlinx.kover.gradle.plugin.commons.KoverIllegalConfigException import org.gradle.api.Action -import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.provider.Property import org.gradle.api.provider.SetProperty @@ -125,6 +124,9 @@ public interface KoverVariantConfig { * * // exclude source classes of specified source sets from all reports * excludedSourceSets.addAll(excludedSourceSet) + * + * // exclude classes of all non-specified source sets from all reports. + * includedSourceSets.addAll(includedSourceSet) * ``` */ public fun sources(block: Action) @@ -152,6 +154,9 @@ public interface KoverVariantConfig { * * // exclude source classes of specified source sets from all reports * excludedSourceSets.addAll(excludedSourceSet) + * + * // exclude classes of all non-specified source sets from all reports. + * includedSourceSets.addAll(includedSourceSet) * ``` */ @KoverGradlePluginDsl @@ -162,9 +167,20 @@ public interface KoverVariantSources { public val excludeJava: Property /** - * Exclude source classes of specified source sets from all reports + * Exclude source classes of specified source sets from all reports. + * + * `test` source set is excluded by default. */ public val excludedSourceSets: SetProperty + + /** + * Exclude classes of all non-specified source sets from all reports. + * + * Classes from source sets that are not listed here will not be included in the report. + * + * `test` source set can be specified here. + */ + public val includedSourceSets: SetProperty } /** diff --git a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/internal/VariantsImpl.kt b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/internal/VariantsImpl.kt index 0408e906..ee24e5ff 100644 --- a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/internal/VariantsImpl.kt +++ b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/internal/VariantsImpl.kt @@ -23,6 +23,7 @@ internal abstract class KoverCurrentProjectVariantsConfigImpl @Inject constructo init { sources.excludeJava.convention(false) sources.excludedSourceSets.convention(emptySet()) + sources.includedSourceSets.convention(emptySet()) instrumentation.disabledForAll.convention(false) instrumentation.excludedClasses.convention(emptySet()) @@ -91,6 +92,7 @@ internal abstract class KoverVariantConfigImpl @Inject constructor(objects: Obje internal fun deriveFrom(other: KoverVariantConfigImpl) { sources.excludeJava.set(other.sources.excludeJava) sources.excludedSourceSets.addAll(other.sources.excludedSourceSets) + sources.includedSourceSets.addAll(other.sources.includedSourceSets) } }