Skip to content

Commit 0ba9e9e

Browse files
authored
Aligned filtering for JaCoCo reports with Kover reporting
Added support of filtering by annotations and ancestors to the wrapper of the JaCoCo reporter. Upgraded the default JaCoCo version to `0.8.14` PR #770
1 parent f182e70 commit 0ba9e9e

File tree

20 files changed

+569
-103
lines changed

20 files changed

+569
-103
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ maven-embedder = "3.9.8"
1111
maven-api = "3.0"
1212
maven-resolver = "1.9.21"
1313
maven-slf4j = "1.7.36"
14-
jacoco = "0.8.12"
14+
jacoco = "0.8.14"
1515

1616
[libraries]
1717

kover-gradle-plugin/api/kover-gradle-plugin.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ public abstract interface class kotlinx/kover/gradle/plugin/dsl/KoverVerifyTaskC
334334
public final class kotlinx/kover/gradle/plugin/dsl/KoverVersions {
335335
public static final field INSTANCE Lkotlinx/kover/gradle/plugin/dsl/KoverVersions;
336336
public static final field JACOCO_TOOL_DEFAULT_VERSION Ljava/lang/String;
337+
public static final field JACOCO_TOOL_MINIMAL_VERSION Ljava/lang/String;
337338
public static final field MINIMUM_GRADLE_VERSION Ljava/lang/String;
338339
public final fun getVersion ()Ljava/lang/String;
339340
}

kover-gradle-plugin/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ dependencies {
4646
// exclude transitive dependency on stdlib, the Gradle version should be used
4747
compileOnly(kotlin("stdlib"))
4848
compileOnly(libs.gradlePlugin.kotlin)
49-
compileOnly(libs.jacoco.reporter)
49+
50+
compileOnly(libs.jacoco.reporter) {
51+
// use ASM from JaCoCo for compilation
52+
isTransitive = true
53+
}
5054

5155
functionalTestImplementation(kotlin("test"))
5256
functionalTestImplementation(libs.junit.jupiter)

kover-gradle-plugin/docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ kover {
12271227
for the custom version
12281228
```kotlin
12291229
kover {
1230-
useJacoco("0.8.10")
1230+
useJacoco("0.8.14")
12311231
}
12321232
```
12331233

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2017-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.kover.gradle.plugin.test.functional.cases
6+
7+
import kotlinx.kover.gradle.plugin.test.functional.framework.configurator.BuildConfigurator
8+
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.SlicedGeneratedTest
9+
10+
internal class InlineTests {
11+
@SlicedGeneratedTest(allTools = true)
12+
fun BuildConfigurator.testFilteringInline() {
13+
addProjectWithKover {
14+
sourcesFrom("inlines")
15+
kover {
16+
reports.filters.excludes.classes("*.TestingClass")
17+
}
18+
}
19+
20+
run("koverXmlReport") {
21+
xmlReport {
22+
methodCounter("org.jetbrains.ClassWithInline", "main", type = "LINE").assertFullyCovered()
23+
classCounter("org.jetbrains.TestingClass").assertAbsent()
24+
}
25+
}
26+
}
27+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2017-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.kover.gradle.plugin.test.functional.cases
6+
7+
import kotlinx.kover.gradle.plugin.commons.CoverageToolVendor
8+
import kotlinx.kover.gradle.plugin.dsl.AggregationType
9+
import kotlinx.kover.gradle.plugin.test.functional.framework.configurator.BuildConfigurator
10+
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.GeneratedTest
11+
12+
internal class JacocoTests {
13+
@GeneratedTest(tool = CoverageToolVendor.JACOCO)
14+
fun BuildConfigurator.testMinimalVersion() {
15+
addProjectWithKover {
16+
sourcesFrom("simple")
17+
kover {
18+
useJacoco("0.8.7")
19+
}
20+
21+
kover {
22+
reports {
23+
filters {
24+
excludes {
25+
classes("org.jetbrains.*Exa?ple*")
26+
}
27+
}
28+
verify {
29+
rule {
30+
// without ExampleClass covered lines count = 2, but 4 with it
31+
maxBound(2, aggregationForGroup = AggregationType.COVERED_COUNT)
32+
}
33+
}
34+
}
35+
}
36+
}
37+
run("koverXmlReport", "koverVerify") {
38+
xmlReport {
39+
classCounter("org.jetbrains.ExampleClass").assertAbsent()
40+
classCounter("org.jetbrains.SecondClass").assertCovered()
41+
}
42+
}
43+
}
44+
}

kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/ReportAnnotationFilterTests.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import kotlinx.kover.gradle.plugin.dsl.*
88
import kotlinx.kover.gradle.plugin.dsl.CoverageUnit.LINE
99
import kotlinx.kover.gradle.plugin.test.functional.framework.configurator.*
1010
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.*
11-
import java.io.Closeable
12-
1311

1412
internal class ReportAnnotationFilterTests {
1513

16-
@GeneratedTest
14+
@SlicedGeneratedTest(allTools = true)
1715
fun BuildConfigurator.testExclusions() {
1816
addProjectWithKover {
1917
sourcesFrom("annotations-main")
@@ -40,7 +38,7 @@ internal class ReportAnnotationFilterTests {
4038
}
4139
}
4240

43-
@GeneratedTest
41+
@SlicedGeneratedTest(allTools = true)
4442
fun BuildConfigurator.testInclusions() {
4543
addProjectWithKover {
4644
sourcesFrom("annotations-mix")
@@ -74,7 +72,7 @@ internal class ReportAnnotationFilterTests {
7472
}
7573
}
7674

77-
@GeneratedTest
75+
@SlicedGeneratedTest(allTools = true)
7876
fun BuildConfigurator.testOverride() {
7977
addProjectWithKover {
8078
sourcesFrom("annotations-main")
@@ -91,7 +89,7 @@ internal class ReportAnnotationFilterTests {
9189
coverageUnits.set(LINE)
9290
aggregationForGroup.set(AggregationType.COVERED_COUNT)
9391
minValue.set(15)
94-
maxValue.set(15)
92+
maxValue.set(16)
9593
}
9694
}
9795
}

kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/ReportInheritedFromFilterTests.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
package kotlinx.kover.gradle.plugin.test.functional.cases
66

77
import kotlinx.kover.gradle.plugin.test.functional.framework.configurator.BuildConfigurator
8-
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.GeneratedTest
8+
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.SlicedGeneratedTest
99

1010
internal class ReportInheritedFromFilterTests {
11-
@GeneratedTest
11+
@SlicedGeneratedTest(allTools = true)
1212
fun BuildConfigurator.testExclusions() {
1313
addProjectWithKover {
1414
sourcesFrom("inherited-main")
@@ -40,7 +40,7 @@ internal class ReportInheritedFromFilterTests {
4040
}
4141
}
4242

43-
@GeneratedTest
43+
@SlicedGeneratedTest(allTools = true)
4444
fun BuildConfigurator.testInclusions() {
4545
addProjectWithKover {
4646
sourcesFrom("inherited-main")
@@ -72,7 +72,7 @@ internal class ReportInheritedFromFilterTests {
7272
}
7373
}
7474

75-
@GeneratedTest
75+
@SlicedGeneratedTest(allTools = true)
7676
fun BuildConfigurator.testIncludeAndExclude() {
7777
addProjectWithKover {
7878
sourcesFrom("inherited-main")
@@ -108,7 +108,7 @@ internal class ReportInheritedFromFilterTests {
108108
}
109109
}
110110

111-
@GeneratedTest
111+
@SlicedGeneratedTest(allTools = true)
112112
fun BuildConfigurator.testDifferentIncludeFilters() {
113113
addProjectWithKover {
114114
sourcesFrom("inherited-main")
@@ -119,6 +119,7 @@ internal class ReportInheritedFromFilterTests {
119119
// for includes 'AND' rule should work
120120
inheritedFrom("org.jetbrains.A")
121121
classes("*.*Child")
122+
annotatedBy("*.MyAnnotation")
122123
}
123124
}
124125
}
@@ -129,13 +130,13 @@ internal class ReportInheritedFromFilterTests {
129130
xmlReport {
130131
classCounter("org.jetbrains.A").assertAbsent()
131132
classCounter("org.jetbrains.B").assertAbsent()
133+
classCounter("org.jetbrains.AChild").assertAbsent()
132134

133135
classCounter("org.jetbrains.BChild").assertFullyMissed()
134-
classCounter("org.jetbrains.AChild").assertFullyMissed()
135136
}
136137
}
137138
}
138-
@GeneratedTest
139+
@SlicedGeneratedTest(allTools = true)
139140
fun BuildConfigurator.testDifferentExcludeFilters() {
140141
addProjectWithKover {
141142
sourcesFrom("inherited-main")

kover-gradle-plugin/src/functionalTest/templates/sources/inherited-main/main/kotlin/Sources.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class AChild: A() {
4848
}
4949
}
5050

51+
@MyAnnotation
5152
// indirect inheritance of project class
5253
class BChild: B() {
5354
fun functionBB() {
@@ -79,3 +80,5 @@ class CloseableClass : Closeable {
7980
println("foo")
8081
}
8182
}
83+
84+
annotation class MyAnnotation
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.jetbrains
2+
3+
class ClassWithInline {
4+
inline fun main(block: () -> Unit) {
5+
block()
6+
println("first")
7+
println("second")
8+
}
9+
}
10+
11+
class TestingClass {
12+
fun test() {
13+
ClassWithInline().main { println("") }
14+
}
15+
}
16+

0 commit comments

Comments
 (0)