-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
148 lines (125 loc) · 4.38 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
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import javax.xml.parsers.DocumentBuilderFactory
val kermitVersion: String by project
val ktorVersion: String by project
plugins {
kotlin("multiplatform") version "1.9.10"
kotlin("plugin.serialization") version "1.9.10"
id("com.vanniktech.maven.publish") version "0.25.3"
id("io.gitlab.arturbosch.detekt") version "1.23.0"
id("org.jetbrains.kotlinx.kover") version "0.7.4"
id("org.jlleitschuh.gradle.ktlint") version "11.5.0"
id("org.jetbrains.dokka") version "1.8.20"
}
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
gradlePluginPortal()
mavenCentral()
}
@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
jvm {
compilations.all {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict", "-opt-in=kotlin.RequiresOptIn")
jvmTarget = "1.8"
}
}
}
targetHierarchy.default()
linuxX64()
linuxArm64()
macosX64()
macosArm64()
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-websockets:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("org.jetbrains.kotlinx:atomicfu:0.22.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")
implementation("org.slf4j:slf4j-simple:2.0.7")
api("co.touchlab:kermit:$kermitVersion")
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("reflect"))
}
}
val jvmMain by getting {
dependencies {
implementation("io.ktor:ktor-client-cio-jvm:$ktorVersion")
}
}
val jvmTest by getting
val nativeMain by getting {
dependencies {
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
}
val nativeTest by getting
}
}
tasks.create<Delete>("cleanDokka") {
delete = setOf(
layout.buildDirectory.dir("dokka"),
)
}
tasks.withType<DokkaTask>().configureEach {
dependsOn("cleanDokka")
}
// Taken from https://bitspittle.dev/blog/2022/koverbadge
tasks.register("printLineCoverage") {
group = "verification" // Put into the same group as the `kover` tasks
dependsOn("koverXmlReport")
doLast {
val report = layout.buildDirectory.file("/reports/kover/report.xml")
val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(report.get().asFile)
val rootNode = doc.firstChild
var childNode = rootNode.firstChild
var coveragePercent = 0.0
while (childNode != null) {
if (childNode.nodeName == "counter") {
val typeAttr = childNode.attributes.getNamedItem("type")
if (typeAttr.textContent == "LINE") {
val missedAttr = childNode.attributes.getNamedItem("missed")
val coveredAttr = childNode.attributes.getNamedItem("covered")
val missed = missedAttr.textContent.toLong()
val covered = coveredAttr.textContent.toLong()
coveragePercent = (covered * 100.0) / (missed + covered)
break
}
}
childNode = childNode.nextSibling
}
println("%.1f".format(coveragePercent))
}
}
tasks {
check {
finalizedBy(
koverHtmlReport,
)
}
}
mavenPublishing {
// If any issues arise with publishing, check here:
// https://s01.oss.sonatype.org/#stagingRepositories
version = System.getenv("VERSION")
signAllPublications()
}
detekt {
config.setFrom("$projectDir/config/detekt-config.yml")
}
ktlint {
version.set("0.50.0")
ignoreFailures.set(false)
}