-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
116 lines (100 loc) · 3.65 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
import javax.xml.parsers.DocumentBuilderFactory
plugins {
kotlin("jvm") version "2.0.0"
id("org.jetbrains.kotlinx.kover") version "0.8.1"
id("org.jetbrains.dokka") version "1.9.20"
`maven-publish`
}
group = "dev.starry.ktscheduler"
version = "1.1.6"
repositories {
mavenCentral()
}
dependencies {
// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
// Testing
testImplementation(kotlin("test"))
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1")
testImplementation("org.mockito:mockito-core:4.6.1")
testImplementation("org.mockito:mockito-inline:4.6.1")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:2.0.0")
}
kover {
reports {
// Require 95% minimum test coverage.
verify { rule { minBound(95) } }
}
}
val dokkaHtml by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class)
val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
dependsOn(dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaHtml.outputDirectory)
}
val sourcesJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
publishing {
publications {
register("mavenJava", MavenPublication::class) {
groupId = group.toString()
artifactId = "ktscheduler"
version = version.toString()
from(components["java"])
pom {
name.set("KtScheduler")
description.set("Coroutine-based task/job scheduler for Kotlin.")
url.set("https://github.com/Pool-Of-Tears/KtScheduler")
licenses {
license {
name.set("Apache-2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("starry-shivam")
name.set("Starry Shivam")
email.set("starry@krsh.dev")
}
}
}
afterEvaluate {
// Add Javadoc JAR to the publication.
artifact(javadocJar)
// Add sources JAR to the publication.
artifact(sourcesJar)
}
}
}
}
// Print line coverage percentage to console, so we can generate badge in CI.
tasks.register("printLineCoverage") {
group = "verification"
dependsOn("koverXmlReport")
doLast {
val report = file("${layout.buildDirectory.get()}/reports/kover/report.xml")
val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(report)
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()
// Calculate coverage percentage.
coveragePercent = (covered * 100.0) / (missed + covered)
break
}
}
childNode = childNode.nextSibling
}
println("%.1f".format(coveragePercent))
}
}