• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 import kotlinx.kover.gradle.plugin.dsl.*
2 
3 /*
4  * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
5  */
<lambda>null6 plugins {
7     id("org.jetbrains.kotlinx.kover")
8 }
9 
10 val notCovered = sourceless + internal + unpublished
11 
12 val expectedCoverage = mutableMapOf(
13     // These have lower coverage in general, it can be eventually fixed
14     "kotlinx-coroutines-swing" to 70, // awaitFrame is not tested
15     "kotlinx-coroutines-javafx" to 35, // JavaFx is not tested on TC because its graphic subsystem cannot be initialized in headless mode
16 
17     // Reactor has lower coverage in general due to various fatal error handling features
18     "kotlinx-coroutines-reactor" to 75
19 )
20 
21 val conventionProject = project
22 
<lambda>null23 subprojects {
24     val projectName = name
25     if (projectName in notCovered) return@subprojects
26 
27     project.apply(plugin = "org.jetbrains.kotlinx.kover")
28     conventionProject.dependencies.add("kover", this)
29 
30     extensions.configure<KoverProjectExtension>("kover") {
31         /*
32         * Is explicitly enabled on TC in a separate build step.
33         * Examples:
34         * ./gradlew :p:check -- doesn't verify coverage
35         * ./gradlew :p:check -Pkover.enabled=true -- verifies coverage
36         * ./gradlew :p:koverHtmlReport -Pkover.enabled=true -- generates HTML report
37         */
38         if (properties["kover.enabled"]?.toString()?.toBoolean() != true) {
39             disable()
40         }
41     }
42 
43     extensions.configure<KoverReportExtension>("koverReport") {
44         defaults {
45             html {
46                 setReportDir(conventionProject.layout.buildDirectory.dir("kover/${project.name}/html"))
47             }
48 
49             verify {
50                 rule {
51                     /*
52                     * 85 is our baseline that we aim to raise to 90+.
53                     * Missing coverage is typically due to bugs in the agent
54                     * (e.g. signatures deprecated with an error are counted),
55                     * sometimes it's various diagnostic `toString` or `catch` for OOMs/VerificationErrors,
56                     * but some places are definitely worth visiting.
57                     */
58                     minBound(expectedCoverage[projectName] ?: 85) // COVERED_LINES_PERCENTAGE
59                 }
60             }
61         }
62     }
63 }
64 
<lambda>null65 koverReport {
66     defaults {
67         verify {
68             rule {
69                 minBound(85) // COVERED_LINES_PERCENTAGE
70             }
71         }
72     }
73 }
74 
<lambda>null75 conventionProject.tasks.register("koverReport") {
76     dependsOn(conventionProject.tasks.named("koverHtmlReport"))
77 }
78