-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle.kts
157 lines (135 loc) · 4.32 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import io.github.gradlenexus.publishplugin.NexusPublishExtension
import kotlinx.kover.gradle.plugin.dsl.KoverProjectExtension
import kotlinx.kover.gradle.plugin.dsl.tasks.KoverXmlReport
plugins {
id("yatagan.base-module")
id("org.jetbrains.kotlinx.kover")
}
val yataganVersion: String by extra
val enableCoverage: Boolean by extra
val isUnderTeamcity = providers.environmentVariable("TEAMCITY_VERSION").isPresent
val nexusUsername: Provider<String> = providers.environmentVariable("NEXUS_USERNAME")
val nexusPassword: Provider<String> = providers.environmentVariable("NEXUS_PASSWORD")
if (nexusUsername.isPresent && nexusPassword.isPresent) {
apply(plugin = "io.github.gradle-nexus.publish-plugin")
extensions.configure<NexusPublishExtension> {
this.repositories {
sonatype {
nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
username.set(nexusUsername)
password.set(nexusPassword)
packageGroup.set("com.yandex.yatagan")
}
}
}
}
tasks {
if (isUnderTeamcity) {
register("publish") {
doLast {
println("##teamcity[buildStatus text='${yataganVersion}: {build.status.text}']")
}
}
}
}
kover {
reports {
filters {
includes {
classes("com.yandex.yatagan.**")
}
excludes {
classes(
// Do not cover internal stuff
"**.internal.**",
// Mostly inline utility code
"**.ExtensionsKt",
// Testing code
"com.yandex.yatagan.testing.**",
// Code generation utility code
"com.yandex.yatagan.codegen.poetry.**",
// Just in case some build code gets instrumented
"com.yandex.yatagan.gradle.**",
)
}
}
}
}
val projectsToCover = setOf(
":api:public",
":api:dynamic",
":validation:impl",
":validation:format",
":lang:common",
":lang:compiled",
":lang:jap",
":lang:rt",
":lang:ksp",
":core:model:impl",
":core:graph:impl",
":processor:common",
":processor:jap",
":processor:ksp",
":rt:engine",
":rt:support",
":codegen:impl",
":testing:tests",
)
val projectsNotToCover = setOf(
// Do not cover utility
":base:api",
":base:impl",
// Do not cover "api" artefacts, as they contain no logic but sometimes can mess with the numbers
":api:compiled", // DEPRECATED
":validation:api",
":validation:spi",
":lang:api",
":core:model:api",
":core:graph:api",
// Do not cover codegen utility
":codegen:poetry",
// Do not cover testing harness
":testing:procedural",
":testing:source-set",
)
projectsNotToCover.intersect(projectsToCover).let { ambiguous ->
check(ambiguous.isEmpty()) {
"Code coverage configuration for $ambiguous projects is ambiguous. " +
"Ensure each project path is present in only one list"
}
}
fun KoverProjectExtension.configureKover() {
// IntelliJ engine yields weird results with uncovered empty lines.
// Results from Jacoco are pretty accurate.
useJacoco()
}
if (enableCoverage) {
kover.configureKover()
subprojects {
when (path) {
in projectsToCover -> {
apply(plugin = "org.jetbrains.kotlinx.kover")
extensions.getByType<KoverProjectExtension>().configureKover()
}
in projectsNotToCover -> {
// Okay, explicitly skip it
}
else -> afterEvaluate {
// If the project contains code (not a "namespace" project)
if (plugins.hasPlugin("java")) {
throw GradleException("Please, decide whether to enable code coverage for '$path' project " +
"and put it into the appropriate list")
}
}
}
}
dependencies {
projectsToCover.forEach {
kover(project(it))
}
}
tasks.check {
dependsOn(tasks.withType<KoverXmlReport>())
}
}