Repository navigation
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
367 lines (347 loc) · 12.5 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
367 lines (347 loc) · 12.5 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
* Copyright 2025 Bloomberg Finance L.P.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import info.solidsoft.gradle.pitest.PitestPlugin
import info.solidsoft.gradle.pitest.PitestPluginExtension
import io.gitlab.arturbosch.detekt.DetektPlugin
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import java.net.URI
import kotlinx.kover.gradle.plugin.dsl.AggregationType
import org.gradle.api.JavaVersion
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.gradle.ext.copyright
import org.jetbrains.gradle.ext.settings
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.tasks.GenerateReportsTask
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
import java.time.Duration
buildscript {
dependencies {
classpath(libs.atomicfu)
}
}
plugins {
base
alias(libs.plugins.cyclonedx) apply false
alias(libs.plugins.dokka)
alias(libs.plugins.kover)
alias(libs.plugins.pitest) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.ktlint)
alias(libs.plugins.dependencyCheck) apply false
alias(libs.plugins.ideaExt)
alias(libs.plugins.nmcp)
}
logger.quiet("Group: {}; Version: {}", group, version)
val publishedSbomProjects = listOf(
":pushiko-api",
":pushiko-apns",
":pushiko-commons",
":pushiko-fcm",
":pushiko-health",
":pushiko-http",
":pushiko-json",
":pushiko-metrics",
":pushiko-netty-ktx",
":pushiko-pools"
)
nmcpAggregation {
centralPortal {
username.set(providers.gradleProperty("centralPortalUsername"))
password.set(providers.gradleProperty("centralPortalPassword"))
publishingType.set("AUTOMATIC")
validationTimeout.set(Duration.ofMinutes(30L))
publishingTimeout.set(Duration.ofMinutes(30L))
}
}
dependencies {
kover(projects.pushikoApi)
kover(projects.pushikoApns)
kover(projects.pushikoFcm)
kover(projects.pushikoCommons)
kover(projects.pushikoHealth)
kover(projects.pushikoHttp)
kover(projects.pushikoJson)
kover(projects.pushikoMetrics)
kover(projects.pushikoNettyKtx)
kover(projects.pushikoPools)
listOf(
projects.pushikoApi,
projects.pushikoApns,
projects.pushikoCommons,
projects.pushikoFcm,
projects.pushikoHealth,
projects.pushikoHttp,
projects.pushikoJson,
projects.pushikoMetrics,
projects.pushikoNettyKtx,
projects.pushikoPools
).forEach {
add("nmcpAggregation", it)
}
}
subprojects {
group = rootProject.group
plugins.withId("maven-publish") {
pluginManager.apply("com.gradleup.nmcp")
}
apply {
plugin("org.jlleitschuh.gradle.ktlint")
plugin("org.owasp.dependencycheck")
}
plugins.withType<JavaPlugin>().configureEach {
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_11
withSourcesJar()
}
dependencies {
"implementation"(platform(libs.kotlinx.coroutines.bom))
constraints.add("runtimeOnly", libs.netty.all) {
version {
reject("[0, 4.1.85.Final]")
because("CVE-2022-41881 Stack exhaustion; CVE-2022-41915 HTTP Response splitting")
}
}
}
}
tasks.withType<JavaCompile>().configureEach {
targetCompatibility = JavaVersion.VERSION_11.toString()
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
allWarningsAsErrors = true
freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
jvmTarget = "11"
}
}
tasks.withType<Jar>().configureEach {
manifest {
attributes(mapOf("Bundle-License" to "Apache-2.0;link=\"https://www.apache.org/licenses/LICENSE-2.0\""))
}
metaInf {
from("$rootDir/LICENSE")
}
}
tasks.withType<Test>().configureEach {
testLogging {
events(TestLogEvent.FAILED, TestLogEvent.SKIPPED)
exceptionFormat = TestExceptionFormat.FULL
showCauses = true
showExceptions = true
showStackTraces = true
}
useJUnitPlatform()
mapOf(
"junit.jupiter.execution.timeout.lifecycle.method.default" to "60s",
"junit.jupiter.execution.timeout.mode" to "disabled_on_debug",
"junit.jupiter.execution.timeout.testable.method.default" to "60s"
).forEach {
systemProperty(it.key, it.value)
}
jvmArgs(
"-Dio.netty.leakDetection.level=paranoid",
"--add-exports=java.base/sun.security.x509=ALL-UNNAMED"
)
}
plugins.withType<PitestPlugin> {
configure<PitestPluginExtension> {
junit5PluginVersion.set("1.1.0")
targetClasses.set(listOf("com.bloomberg.*"))
}
}
plugins.withType<DetektPlugin> {
configure<DetektExtension> {
source.from(files("src"))
config.from(files("${rootProject.projectDir}/config/detekt/config.yml"))
buildUponDefaultConfig = true
parallel = false
debug = false
ignoreFailures = false
}
}
plugins.withType<DokkaPlugin> {
tasks.register<Jar>("dokkaHtmlJar") {
dependsOn(tasks.dokkaHtml)
from(tasks.dokkaHtml.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}
}
tasks.withType<DokkaTask>().configureEach {
moduleName.set("Pushiko")
dokkaSourceSets.named("main") {
sourceLink {
remoteUrl.set(URI.create("https://github.com/bloomberg/pushiko/tree/main/${project.name}/src").toURL())
localDirectory.set(projectDir.resolve("src"))
remoteLineSuffix.set("#L")
}
perPackageOption {
documentedVisibilities.addAll(
DokkaConfiguration.Visibility.INTERNAL,
DokkaConfiguration.Visibility.PUBLIC
)
}
includeNonPublic.set(false)
jdkVersion.set(JavaVersion.VERSION_11.majorVersion.toInt())
noJdkLink.set(false)
noStdlibLink.set(false)
if (project.file("Module.md").exists()) {
includes.from(project.file("Module.md"))
}
}
}
}
allprojects {
ktlint {
disabledRules.set(setOf("import-ordering", "indent", "wrapping")) // FIXME ?
reporters {
reporter(ReporterType.HTML)
}
}
tasks.withType<GenerateReportsTask>().configureEach {
reportsOutputDirectory.set(rootProject.layout.buildDirectory.dir("reports/ktlint/${project.name}/$name"))
}
}
koverReport {
filters {
excludes {
classes(
"io.netty.*",
"*.jmh_generated.*",
"*\$\$*",
"*Benchmark",
"*Fixture",
"*FixtureKt*",
"*Test*"
)
}
}
defaults {
verify {
rule("Minimal coverage") {
bound {
minValue = 80
aggregation = AggregationType.COVERED_PERCENTAGE
}
}
}
}
}
tasks.named("check") {
dependsOn("koverVerify")
}
tasks.register("checkSemver") {
group = "verification"
description = "Binary-compatibility check across all published modules."
}
tasks.register("jvmFuzz") {
group = "verification"
description = "Runs JVM fuzzing; configure with -Ppushiko.fuzz.profile=smoke|release|scheduled."
dependsOn(":pushiko-http:jvmFuzz", ":pushiko-json:jvmFuzz")
}
val cyclonedxBom = tasks.register("cyclonedxBom") {
group = "reporting"
description = "Generates the final CycloneDX SBOM for every published JVM artifact."
dependsOn(publishedSbomProjects.map { "$it:cyclonedxFinalBom" })
}
tasks.register("repositoryCyclonedxBom") {
group = "reporting"
description = "Merges the published module SBOMs into one repository CycloneDX SBOM."
dependsOn(cyclonedxBom)
val sbomFiles = publishedSbomProjects.map { projectPath ->
project(projectPath).layout.buildDirectory.file(
"reports/cyclonedx-direct/${project(projectPath).name}-${project(projectPath).version}-cyclonedx.json"
)
}
inputs.files(sbomFiles)
val output = layout.buildDirectory.file("reports/cyclonedx/pushiko-$version.cdx.json")
outputs.file(output)
doLast {
val parser = JsonSlurper()
val documents = sbomFiles.map { parser.parse(it.get().asFile) as Map<*, *> }
val first = documents.first().toMutableMap()
val rootReference = "com.bloomberg.pushiko:pushiko"
val moduleComponents = documents.map { document ->
((document["metadata"] as Map<*, *>)["component"] as Map<*, *>)
}
first["serialNumber"] = "urn:uuid:${java.util.UUID.randomUUID()}"
first["metadata"] = (first["metadata"] as Map<*, *>).toMutableMap().apply {
put("component", mapOf(
"type" to "library",
"bom-ref" to rootReference,
"group" to "com.bloomberg.pushiko",
"name" to "pushiko",
"version" to project.version.toString()
))
}
val components = linkedMapOf<String, Map<*, *>>()
val dependencies = linkedMapOf<String, LinkedHashSet<String>>()
moduleComponents.forEach { component ->
components[component["bom-ref"].toString()] = component
}
documents.forEach { document ->
(document["components"] as? List<*>)?.filterIsInstance<Map<*, *>>()?.forEach { component ->
components[component["bom-ref"].toString()] = component
}
(document["dependencies"] as? List<*>)?.filterIsInstance<Map<*, *>>()?.forEach { dependency ->
val ref = dependency["ref"].toString()
val children = dependencies.getOrPut(ref) { linkedSetOf() }
(dependency["dependsOn"] as? List<*>)?.forEach { children += it.toString() }
}
}
dependencies[rootReference] = moduleComponents.mapTo(linkedSetOf()) { it["bom-ref"].toString() }
first["components"] = components.values.sortedBy { it["bom-ref"].toString() }
first["dependencies"] = dependencies.entries.sortedBy { it.key }.map { (ref, children) ->
mapOf("ref" to ref, "dependsOn" to children.sorted())
}
val target = output.get().asFile
target.parentFile.mkdirs()
val generated = JsonOutput.prettyPrint(JsonOutput.toJson(first)) + System.lineSeparator()
val validationErrors = org.cyclonedx.parsers.JsonParser().validate(
generated,
org.cyclonedx.Version.VERSION_16
)
require(validationErrors.isEmpty()) {
"Generated repository CycloneDX SBOM is invalid: ${validationErrors.joinToString()}"
}
target.writeText(generated)
}
}
idea.project.settings {
copyright {
useDefault = "Bloomberg"
profiles {
create("Bloomberg") {
notice = """
Copyright ${'$'}today.year Bloomberg Finance L.P.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
""".trimIndent()
}
}
}
}