|
17 | 17 | // buildSrc/src/main/kotlin/PublishingConventionPlugin.kt |
18 | 18 | import com.vanniktech.maven.publish.AndroidSingleVariantLibrary |
19 | 19 | import com.vanniktech.maven.publish.MavenPublishBaseExtension |
| 20 | +import kotlinx.kover.gradle.plugin.dsl.KoverProjectExtension |
20 | 21 | import org.gradle.api.Plugin |
21 | 22 | import org.gradle.api.Project |
22 | 23 | import org.gradle.kotlin.dsl.* |
23 | | -import org.gradle.testing.jacoco.plugins.JacocoPluginExtension |
24 | | -import org.gradle.api.tasks.testing.Test |
25 | | -import org.gradle.testing.jacoco.plugins.JacocoTaskExtension |
26 | | -import org.gradle.testing.jacoco.tasks.JacocoReport |
27 | 24 |
|
28 | 25 | class PublishingConventionPlugin : Plugin<Project> { |
29 | 26 | override fun apply(project: Project) { |
30 | 27 | project.run { |
31 | 28 |
|
32 | 29 | applyPlugins() |
33 | | - configureJacoco() |
| 30 | + configureKover() |
34 | 31 | configureVanniktechPublishing() |
35 | 32 | } |
36 | 33 | } |
37 | 34 |
|
38 | 35 | private fun Project.applyPlugins() { |
39 | 36 | apply(plugin = "com.android.library") |
40 | 37 | apply(plugin = "org.jetbrains.dokka") |
41 | | - apply(plugin = "org.gradle.jacoco") |
| 38 | + apply(plugin = "org.jetbrains.kotlinx.kover") |
42 | 39 | apply(plugin = "com.vanniktech.maven.publish") |
43 | 40 | } |
44 | 41 |
|
45 | | - private fun Project.configureJacoco() { |
46 | | - configure<JacocoPluginExtension> { |
47 | | - toolVersion = "0.8.15" // Compatible with newer JDKs |
48 | | - } |
49 | | - |
50 | | - // AGP 9.0+ built-in Jacoco support or manual configuration. |
51 | | - // We create a "jacocoTestReport" task to match the CI workflow. |
52 | | - |
53 | | - tasks.register<JacocoReport>("jacocoTestReport") { |
54 | | - // Dependencies |
55 | | - dependsOn("testDebugUnitTest") |
56 | | - |
57 | | - reports { |
58 | | - xml.required.set(true) |
59 | | - html.required.set(true) |
60 | | - } |
61 | | - |
62 | | - // Source directories |
63 | | - val mainSrc = "${layout.projectDirectory}/src/main/java" |
64 | | - sourceDirectories.setFrom(files(mainSrc)) |
65 | | - |
66 | | - // Class directories - AGP 9's built-in Kotlin compiler outputs to |
67 | | - // intermediates/built_in_kotlinc/, not the legacy tmp/kotlin-classes/ path. |
68 | | - classDirectories.setFrom( |
69 | | - fileTree(layout.buildDirectory.dir("intermediates/built_in_kotlinc/debug")) { |
70 | | - include("**/classes/**") |
71 | | - }, |
72 | | - fileTree(layout.buildDirectory.dir("intermediates/javac/debug")) { |
73 | | - include("**/classes/**") |
74 | | - exclude("**/R.class", "**/R\$*.class", "**/BuildConfig.class") |
75 | | - } |
76 | | - ) |
77 | | - |
78 | | - // Execution data from the unit test task |
79 | | - executionData.setFrom(fileTree(layout.buildDirectory.get()) { |
80 | | - include("outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec") |
81 | | - }) |
| 42 | + private fun Project.configureKover() { |
| 43 | + configure<KoverProjectExtension> { |
| 44 | + reports { |
| 45 | + filters { |
| 46 | + excludes { |
| 47 | + androidGeneratedClasses() |
| 48 | + } |
| 49 | + } |
| 50 | + } |
82 | 51 | } |
83 | 52 | } |
84 | 53 |
|
|
0 commit comments