-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
230 lines (213 loc) · 8.22 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
230 lines (213 loc) · 8.22 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// SPDX-FileCopyrightText: 2026 Xquik contributors
//
// SPDX-License-Identifier: Apache-2.0
import com.github.jk1.license.filter.DependencyFilter
import com.github.jk1.license.filter.SpdxLicenseBundleNormalizer
import com.github.jk1.license.render.CsvReportRenderer
import com.github.jk1.license.render.InventoryHtmlReportRenderer
import com.github.jk1.license.render.ReportRenderer
import org.gradle.testing.jacoco.tasks.JacocoCoverageVerification
import org.gradle.testing.jacoco.tasks.JacocoReport
plugins {
id("com.github.jk1.dependency-license-report") version "3.1.4"
jacoco
}
repositories {
mavenCentral()
}
jacoco {
toolVersion = "0.8.15"
}
licenseReport {
configurations = arrayOf("runtimeClasspath", "testRuntimeClasspath")
allowedLicensesFile = layout.projectDirectory.file("config/allowed-licenses.json")
filters = arrayOf<DependencyFilter>(SpdxLicenseBundleNormalizer())
renderers =
arrayOf<ReportRenderer>(
CsvReportRenderer("dependencies.csv"),
InventoryHtmlReportRenderer("index.html", "Xquik Java SDK Dependencies"),
)
}
allprojects {
group = "com.xquik.api"
version = "0.10.3" // x-release-please-version
dependencyLocking {
lockAllConfigurations()
}
configurations.configureEach {
resolutionStrategy.force(
"com.fasterxml.jackson.core:jackson-annotations:2.22",
"com.fasterxml.jackson.core:jackson-core:2.22.1",
"com.fasterxml.jackson.core:jackson-databind:2.22.1",
"com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.22.1",
"com.fasterxml.jackson.module:jackson-module-kotlin:2.22.1",
"com.github.jknack:handlebars:4.5.4",
"com.google.guava:guava:33.6.0-jre",
"com.jayway.jsonpath:json-path:3.0.0",
"commons-fileupload:commons-fileupload:1.6.0",
"commons-io:commons-io:2.22.0",
"net.minidev:json-smart:2.6.0",
"org.apache.commons:commons-lang3:3.20.0",
"org.apache.logging.log4j:log4j-api:2.26.1",
"org.apache.logging.log4j:log4j-core:2.26.1",
"org.apache.httpcomponents.client5:httpclient5:5.6.4",
"org.apache.httpcomponents.core5:httpcore5:5.4.3",
"org.apache.httpcomponents.core5:httpcore5-h2:5.4.3",
"org.jsoup:jsoup:1.23.1",
"org.xmlunit:xmlunit-core:2.13.0",
"org.xmlunit:xmlunit-legacy:2.13.0",
"org.xmlunit:xmlunit-placeholders:2.13.0",
)
}
}
subprojects {
// These are populated with dependencies by `buildSrc` scripts.
tasks.register("format") {
group = "Verification"
description = "Formats all source files."
}
tasks.register("lint") {
group = "Verification"
description = "Verifies all source files are formatted."
}
}
val coverageExecutionData =
fileTree(rootDir) {
include("x-twitter-scraper-java*/build/jacoco/test.exec")
}
val coverageProjects =
subprojects.filterNot { it.name == "x-twitter-scraper-java-proguard-test" }
val allCoverageClasses =
files(
coverageProjects.flatMap { project ->
listOf(
project.layout.buildDirectory.dir("classes/java/main"),
project.layout.buildDirectory.dir("classes/kotlin/main"),
)
}
)
val generatedSourceHeaderPrefix = "// File generated from our OpenAPI spec"
val generatedSourceHeaderLineLimit = 12
val maintainedGeneratedSources =
setOf(
"x-twitter-scraper-java-core/src/main/kotlin/com/x_twitter_scraper/api/core/http/RetryingHttpClient.kt"
)
val generatedCoverageExclusions =
coverageProjects.associateWith { project ->
listOf("src/main/java", "src/main/kotlin").flatMap { sourcePath ->
val sourceRoot = project.file(sourcePath)
if (!sourceRoot.isDirectory) {
emptyList()
} else {
sourceRoot
.walkTopDown()
.filter { it.isFile && it.extension in setOf("java", "kt") }
.filter { source ->
source.useLines { lines ->
lines
.take(generatedSourceHeaderLineLimit)
.any { it.startsWith(generatedSourceHeaderPrefix) }
} &&
source.relativeTo(rootDir).invariantSeparatorsPath !in
maintainedGeneratedSources
}
.map { source ->
source
.relativeTo(sourceRoot)
.invariantSeparatorsPath
.substringBeforeLast('.') + "*"
}
.toList()
}
}
}
val maintainedCoverageClasses =
files(
coverageProjects.flatMap { project ->
val exclusions = generatedCoverageExclusions.getValue(project)
listOf(
project.fileTree(project.layout.buildDirectory.dir("classes/java/main")) {
exclude(exclusions)
},
project.fileTree(project.layout.buildDirectory.dir("classes/kotlin/main")) {
exclude(exclusions)
},
)
}
)
val coverageSources =
files(
coverageProjects.flatMap { project ->
listOf(
project.layout.projectDirectory.dir("src/main/java"),
project.layout.projectDirectory.dir("src/main/kotlin"),
)
}
)
val testTasks =
coverageProjects.map { "${it.path}:test" }
val coverageReport =
tasks.register<JacocoReport>("coverageReport") {
group = "Verification"
description = "Generates aggregate line and branch coverage."
dependsOn(testTasks)
executionData(coverageExecutionData)
classDirectories.setFrom(maintainedCoverageClasses)
sourceDirectories.setFrom(coverageSources)
jacocoClasspath = configurations.named("jacocoAnt").get()
reports {
xml.required.set(true)
xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/coverage/coverage.xml"))
html.required.set(true)
html.outputLocation.set(layout.buildDirectory.dir("reports/jacoco/coverage/html"))
csv.required.set(false)
}
}
val coverageRawReport =
tasks.register<JacocoReport>("coverageRawReport") {
group = "Verification"
description = "Reports raw coverage, including generated SDK sources."
dependsOn(testTasks)
executionData(coverageExecutionData)
classDirectories.setFrom(allCoverageClasses)
sourceDirectories.setFrom(coverageSources)
jacocoClasspath = configurations.named("jacocoAnt").get()
reports {
xml.required.set(true)
xml.outputLocation.set(
layout.buildDirectory.file("reports/jacoco/coverage-raw/coverage.xml")
)
html.required.set(true)
html.outputLocation.set(layout.buildDirectory.dir("reports/jacoco/coverage-raw/html"))
csv.required.set(false)
}
}
val coverageVerify =
tasks.register<JacocoCoverageVerification>("coverageVerify") {
group = "Verification"
description = "Enforces aggregate line and branch coverage."
dependsOn(testTasks)
executionData(coverageExecutionData)
classDirectories.setFrom(maintainedCoverageClasses)
sourceDirectories.setFrom(coverageSources)
jacocoClasspath = configurations.named("jacocoAnt").get()
violationRules {
rule {
limit {
counter = "LINE"
value = "COVEREDRATIO"
minimum = "0.90".toBigDecimal()
}
limit {
counter = "BRANCH"
value = "COVEREDRATIO"
minimum = "0.80".toBigDecimal()
}
}
}
}
tasks.register("coverage") {
group = "Verification"
description = "Generates raw coverage and verifies maintained-source coverage."
dependsOn(coverageRawReport, coverageReport, coverageVerify)
}