-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
288 lines (239 loc) · 8.52 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
288 lines (239 loc) · 8.52 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
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.report.ReportMergeTask
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import java.net.URI
group = "io.github.turchenkoalex"
plugins {
`java-library`
`maven-publish`
signing
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlinx.serialization) apply false
alias(libs.plugins.detekt)
alias(libs.plugins.kover)
alias(libs.plugins.nebula.release)
alias(libs.plugins.nexus.publish)
}
allprojects {
repositories {
mavenCentral()
}
// Unit tests settings
tasks.withType<Test> {
reports.html.required = false
reports.junitXml.required = true
// JUnit settings
useJUnitPlatform {
enableAssertions = true
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events = setOf(TestLogEvent.FAILED, TestLogEvent.SKIPPED)
showStandardStreams = false
}
}
}
}
// register task before using in subprojects
val reportMerge by tasks.registering(ReportMergeTask::class) {
output.set(rootProject.layout.buildDirectory.file("reports/detekt/merge.xml"))
}
// Detekt configuration
subprojects {
apply(plugin = "io.gitlab.arturbosch.detekt")
detekt {
buildUponDefaultConfig = true // preconfigure defaults
allRules = false // activate all available (even unstable) rules.
config.setFrom("$rootDir/config/detekt.yml") // point to your custom config defining rules to run, overwriting default behavior
baseline = file("$projectDir/config/baseline.xml") // a way of suppressing issues before introducing detekt
}
tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true) // observe findings in your browser with structure and code snippets
xml.required.set(true) // checkstyle like format mainly for integrations like Jenkins
txt.required.set(false) // similar to the console output, contains issue signature to manually edit baseline files
sarif.required.set(false) // standardized SARIF format (https://sarifweb.azurewebsites.net/) to support integrations with GitHub Code Scanning
md.required.set(false) // simple Markdown format
}
finalizedBy(reportMerge)
}
reportMerge {
input.from(
tasks.withType<Detekt>().map { it.xmlReportFile }
)
}
}
// The main packages
val publishPackages = setOf(
"client",
"core",
"cors",
"jetty",
"json",
"jwt",
"metrics",
"openapi",
"swagger-ui",
"tracing",
"typesafe",
)
// Kover configuration
dependencies {
// register kover for generating merged report from main subprojects
publishPackages.forEach {
kover(project(":$it"))
}
}
subprojects {
if (this.name !in publishPackages) {
return@subprojects
}
apply(plugin = "org.jetbrains.kotlinx.kover")
}
// Publishing configuration
subprojects {
if (this.name !in publishPackages) {
return@subprojects
}
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "signing")
version = sanitizeVersion()
java {
withJavadocJar()
withSourcesJar()
}
configure<PublishingExtension> {
repositories {
maven {
name = "GitHubPackages"
url = URI("https://maven.pkg.github.com/turchenkoalex/kotlet")
credentials {
username = ProjectEnvs.githubActor
password = ProjectEnvs.githubToken
}
}
}
publications {
register<MavenPublication>("gpr") {
from(components["java"])
version = sanitizeVersion()
groupId = "io.github.turchenkoalex"
artifactId = "kotlet-${project.name}"
pom {
name.set("kotlet-${project.name}")
description.set("Kotlet ${project.name} module")
url.set("https://github.com/turchenkoalex/kotlet")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("turchenkoalex")
name.set("Aleksandr Turchenko")
email.set("turchenko@me.com")
}
scm {
connection.set("scm:git:git://github.com/turchenkoalex/kotlet.git")
url.set("https://github.com/turchenkoalex/kotlet")
developerConnection.set("scm:git:ssh://github.com:turchenkoalex/kotlet.git")
}
}
}
}
}
}
signing {
useInMemoryPgpKeys(ProjectEnvs.gpgSigningKey, ProjectEnvs.gpgSigningPassword)
sign(publishing.publications["gpr"])
}
tasks.withType<Sign> {
dependsOn(tasks["build"])
}
tasks {
// All checks were already made by workflow "On pull request" => no checks here
if (gradle.startParameter.taskNames.contains("final")) {
named("build") {
dependsOn.removeIf { it == "check" }
}
}
rootProject.tasks.named("final") {
dependsOn(named("publishToSonatype"))
}
rootProject.tasks.named("devSnapshot") {
dependsOn(named("publishToSonatype"))
}
}
}
nexusPublishing {
repositories {
sonatype {
useStaging.set(!project.isSnapshotVersion())
packageGroup.set("io.github.turchenkoalex")
username.set(ProjectEnvs.sonatypeUsername)
password.set(ProjectEnvs.sonatypePassword)
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
}
}
}
// We want to change SNAPSHOT versions format from:
// <major>.<minor>.<patch>-dev.#+<branchname>.<hash> (local branch)
// <major>.<minor>.<patch>-dev.#+<hash> (github pull request)
// to:
// <major>.<minor>.<patch>-SNAPSHOT
fun Project.sanitizeVersion(): String {
val version = version.toString()
return if (project.isSnapshotVersion()) {
// replace -dev.#+<branchname>.<hash> with -SNAPSHOT
version.replace(Regex("-dev\\..+$"), "-dev-SNAPSHOT")
} else {
version
}
}
fun Project.isSnapshotVersion() = version.toString().contains("-dev")
object ProjectEnvs {
val githubActor: String?
get() = System.getenv("GITHUB_ACTOR")
val githubToken: String?
get() = System.getenv("GITHUB_TOKEN")
val sonatypeUsername: String?
get() = System.getenv("SONATYPE_USERNAME")
val sonatypePassword: String?
get() = System.getenv("SONATYPE_PASSWORD")
val gpgSigningKey: String?
get() = System.getenv("GPG_SIGNING_KEY")
val gpgSigningPassword: String?
get() = System.getenv("GPG_SIGNING_PASSWORD")
}
tasks.register("printDevSnapshotReleaseNote") {
val outputFile = layout.buildDirectory.file("pr-note.txt")
outputs.file(outputFile)
doLast {
val groupId = project.group
val sanitizedVersion = project.sanitizeVersion()
val note = buildString {
appendLine("<!-- PR_NOTE_MARKER -->")
appendLine("\uD83D\uDCE6 New artifacts were published:")
publishPackages.sorted().forEach {
appendLine(" - $groupId:kotlet-$it:$sanitizedVersion")
}
appendLine("")
appendLine("Looks snapshot versions in https://central.sonatype.com/repository/maven-snapshots/ repository")
appendLine("<pre>")
appendLine("repositories {")
appendLine("\tmaven {")
appendLine("\t\turl = uri("https://central.sonatype.com/repository/maven-snapshots/")")
appendLine("\t}")
appendLine("}")
appendLine("</pre>")
}
outputFile.get().asFile.writeText(note)
println(note)
}
dependsOn(tasks["devSnapshot"])
}