-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
81 lines (71 loc) · 2.77 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
81 lines (71 loc) · 2.77 KB
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
plugins {
id("org.springframework.boot") version "4.0.6" apply false
id("io.spring.dependency-management") version "1.1.7" apply false
}
allprojects {
group = "com.corebank"
version = "0.0.2-SNAPSHOT"
repositories {
mavenCentral()
}
}
subprojects {
apply(plugin = "java")
apply(plugin = "jacoco")
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<JacocoReport> {
reports {
xml.required.set(true)
html.required.set(true)
}
}
tasks.named<JacocoCoverageVerification>("jacocoTestCoverageVerification") {
dependsOn("jacocoTestReport")
violationRules {
rule {
limit {
minimum = "0.80".toBigDecimal()
}
}
}
doLast {
val reportFile = project.layout.buildDirectory.file("reports/jacoco/test/jacocoTestReport.xml").get().asFile
if (reportFile.exists()) {
val factory = javax.xml.parsers.DocumentBuilderFactory.newInstance().apply {
setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
setFeature("http://xml.org/sax/features/external-general-entities", false)
setFeature("http://xml.org/sax/features/external-parameter-entities", false)
}
val xml = factory.newDocumentBuilder().parse(reportFile)
val counters = xml.documentElement.childNodes
println("\n${"=".repeat(60)}")
println(" JaCoCo Coverage Summary — :${project.name}")
println("${"=".repeat(60)}")
for (i in 0 until counters.length) {
val node = counters.item(i)
if (node.nodeName == "counter") {
val type = node.attributes.getNamedItem("type").nodeValue
val missed = node.attributes.getNamedItem("missed").nodeValue.toDouble()
val covered = node.attributes.getNamedItem("covered").nodeValue.toDouble()
val total = missed + covered
val pct = if (total > 0) (covered / total) * 100 else 0.0
println(" %-14s %6.2f%% (%s/%s)".format(type, pct, covered.toInt(), total.toInt()))
}
}
println("${"=".repeat(60)}\n")
} else {
println("⚠ JaCoCo XML report not found at: ${reportFile.absolutePath}")
}
}
}
tasks.named("check") {
dependsOn("jacocoTestCoverageVerification")
}
}