-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
126 lines (103 loc) · 3.37 KB
/
build.gradle.kts
File metadata and controls
126 lines (103 loc) · 3.37 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
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
import com.equo.logger.Logger
plugins {
java
jacoco
checkstyle
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}
allprojects {
apply(plugin = "java")
apply(plugin = "jacoco")
apply(plugin = "checkstyle")
group = "dev.equo"
repositories {
mavenCentral()
}
jacoco {
toolVersion = "0.8.11"
}
checkstyle {
toolVersion = "10.3.3"
}
java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11
}
subprojects {
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.jacocoTestReport {
sourceDirectories.setFrom(files(sourceSets["main"].allSource.srcDirs))
classDirectories.setFrom(files(sourceSets["main"].output))
reports {
html.required = false
xml.required = false
csv.required = false
}
}
}
nexusPublishing {
repositories {
sonatype {
nexusUrl = uri("${property("release_url")}")
snapshotRepositoryUrl = uri("${property("snapshot_url")}")
val ossrhUsername = providers
.environmentVariable("OSSRH_USERNAME")
val ossrhPassword = providers
.environmentVariable("OSSRH_PASSWORD")
if (ossrhUsername.isPresent && ossrhPassword.isPresent) {
username = ossrhUsername.get()
password = ossrhPassword.get()
}
}
}
}
// tasks to build jacoco report with results of all subprojects
tasks.register<JacocoReport>("jacocoRootReport") {
val jacocoReportTasks = subprojects.map { subproject ->
subproject.tasks["jacocoTestReport"] as JacocoReport
}
val executionDataMap = jacocoReportTasks.map { jacocoReport ->
jacocoReport.executionData.filter {
it.exists()
}.files
}
executionData.setFrom(executionDataMap)
subprojects.forEach { subproject ->
sourceDirectories.from(files(subproject.sourceSets["main"].allSource.srcDirs))
classDirectories.from(files(subproject.sourceSets["main"].output))
}
reports {
html.required = true
xml.required = true
csv.required = true
}
// Generates reports even when there's no text.exec data, to avoid pipeline failing because of missing artifacts
setOnlyIf {
true
}
}
tasks.register("print-coverage") {
val jacocoRootReport = file("build/reports/jacoco/jacocoRootReport/jacocoRootReport.csv")
var totalInstructions = 0
var totalInstructionCovered = 0
jacocoRootReport.forEachLine { line ->
val fields = line.split(",")
fun getColumn(column: Int): Int {
return fields.getOrNull(column)?.toIntOrNull() ?: 0
}
val instructionMissed = getColumn(3)
val instructionCovered = getColumn(4)
totalInstructions += instructionMissed + instructionCovered
totalInstructionCovered += instructionCovered
}
val percentageInstructionsCovered = if (totalInstructions != 0) {
100 * totalInstructionCovered.toDouble() / totalInstructions
} else {
0.0
}
Logger.info("------------")
Logger.info("$totalInstructionCovered / $totalInstructions instructions covered")
Logger.info("%.2f %% covered".format(percentageInstructionsCovered))
Logger.info("------------")
}