-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
452 lines (406 loc) · 16.2 KB
/
build.gradle.kts
File metadata and controls
452 lines (406 loc) · 16.2 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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import io.github.flaxoos.ktor.extensions.jreleaserGpgPassphrase
import io.github.flaxoos.ktor.extensions.jreleaserGpgPublicKey
import io.github.flaxoos.ktor.extensions.jreleaserGpgSecretKey
import io.github.flaxoos.ktor.extensions.mcPassword
import io.github.flaxoos.ktor.extensions.mcUsername
import org.eclipse.jgit.api.Git
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.SHORT
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
import org.gradle.api.tasks.testing.logging.TestLogging
import org.gradle.api.tasks.testing.logging.TestStackTraceFilter
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jreleaser.gradle.plugin.dsl.deploy.maven.MavenCentralMavenDeployer
import org.jreleaser.gradle.plugin.dsl.deploy.maven.MavenDeployer
import org.jreleaser.gradle.plugin.dsl.deploy.maven.Nexus2MavenDeployer
import org.jreleaser.model.Active.ALWAYS
import org.jreleaser.model.Active.RELEASE
import org.jreleaser.model.Active.SNAPSHOT
import ru.vyarus.gradle.plugin.python.PythonExtension
import java.time.Instant.ofEpochSecond
plugins {
base
id(
libs.plugins.dokka
.get()
.pluginId,
)
id(
libs.plugins.jreleaser
.get()
.pluginId,
)
alias(libs.plugins.mkdocs.build)
alias(libs.plugins.axion.release)
}
// set version based on conventional commit history
scmVersion {
unshallowRepoOnCI.set(false)
tag {
prefix.set("v")
versionSeparator.set("")
}
// Use predefined version creator that handles SNAPSHOT automatically
versionCreator("simple")
// Custom snapshot creator that respects release.mode property
snapshotCreator { version, position ->
val releaseMode = project.findProperty("release.mode")?.toString()
when (releaseMode) {
"release" -> ""
// No suffix for production releases
"snapshot", null -> "-SNAPSHOT"
// Default to snapshot
else -> "-SNAPSHOT"
}
}
// For local development and workflow control, disable tag creation unless explicitly requested
// This prevents markNextVersion from creating unwanted tags
checks {
uncommittedChanges.set(false)
}
// Custom version incrementer based on conventional commits
versionIncrementer { context ->
val git = Git.open(project.rootDir)
try {
val lastTagDesc =
try {
git.describe().setTags(true).call()
} catch (_: Exception) {
null
}
val lastTagName = lastTagDesc?.substringBefore("-")
logger.quiet("[VersionIncrementer] Git describe result: $lastTagDesc")
logger.quiet("[VersionIncrementer] Last tag name: $lastTagName")
// Check if we have any tags at all
val allTags = git.tagList().call()
logger.quiet("[VersionIncrementer] Total tags in repository: ${allTags.size}")
if (allTags.isNotEmpty()) {
logger.quiet("[VersionIncrementer] Available tags: ${allTags.map { it.name.substringAfterLast("/") }}")
}
val repo = git.repository
val head = repo.resolve("HEAD")
val lastTagCommit = lastTagName?.let { repo.resolve("refs/tags/$it^{commit}") }
logger.quiet("[VersionIncrementer] HEAD commit: $head")
logger.quiet("[VersionIncrementer] Last tag commit: $lastTagCommit")
val commits =
if (lastTagCommit != null && head != null) {
logger.quiet("[VersionIncrementer] Getting commits between tag $lastTagName and HEAD")
git
.log()
.addRange(lastTagCommit, head)
.call()
.toList()
} else if (allTags.isEmpty()) {
// If no tags exist at all, this is likely the first release
// Only look at commits since project started being versioned conventionally
logger.quiet("[VersionIncrementer] No tags found - treating as first release, analyzing recent commits only")
if (head != null) {
git
.log()
.add(head)
.setMaxCount(10) // Only look at last 10 commits for first release
.call()
.toList()
} else {
logger.quiet("[VersionIncrementer] No HEAD found, repository appears empty")
emptyList()
}
} else {
// Tags exist but we couldn't resolve the last one
logger.quiet("[VersionIncrementer] Tags exist but couldn't resolve last tag, getting all commits from HEAD")
if (head != null) {
git
.log()
.add(head)
.call()
.toList()
} else {
logger.quiet("[VersionIncrementer] No HEAD found, repository appears empty")
emptyList()
}
}
logger.quiet("[VersionIncrementer] Found ${commits.size} commits since last tag")
if (commits.isNotEmpty()) {
logger.quiet(
"[VersionIncrementer] Commit range: ${
commits.last().name.substring(
0,
7,
)
}..${commits.first().name.substring(0, 7)}",
)
}
var hasMajor = false
var hasMinor = false
var hasPatch = false
val typeRegex = Regex("""^(?<type>\w+)(\([^)]*\))?(?<bang>!)?:\s""", RegexOption.IGNORE_CASE)
val breakingFooter = Regex("""(?im)^BREAKING[ -]CHANGE:""")
for (commit in commits) {
val full = commit.fullMessage.trim()
val subject = full.lineSequence().firstOrNull().orEmpty()
val m = typeRegex.find(subject)
val type =
m
?.groups
?.get("type")
?.value
?.lowercase()
val bang = m?.groups?.get("bang") != null
val breaking = bang || breakingFooter.containsMatchIn(full)
logger.quiet("[VersionIncrementer] Analyzing commit: [${ofEpochSecond(commit.commitTime.toLong())}] $subject")
logger.quiet("[VersionIncrementer] Type: $type, Breaking: $breaking")
when {
breaking -> {
hasMajor = true
logger.quiet("[VersionIncrementer] → Triggers MAJOR version bump (breaking change)")
}
type == "feat" -> {
hasMinor = true
logger.quiet("[VersionIncrementer] → Triggers MINOR version bump (new feature)")
}
type in
setOf(
"fix",
"perf",
"refactor",
"revert",
"docs",
"build",
"chore",
"test",
"style",
"ci",
"task",
)
-> {
hasPatch = true
logger.quiet("[VersionIncrementer] → Triggers PATCH version bump ($type)")
}
else -> {
logger.quiet("[VersionIncrementer] → No version impact")
}
}
}
val v = context.currentVersion
if (commits.isEmpty()) {
logger.quiet("[VersionIncrementer] No commits since last tag → keeping version $v")
return@versionIncrementer v
}
logger.quiet("[VersionIncrementer] Version bump analysis: major=$hasMajor, minor=$hasMinor, patch=$hasPatch")
val newVersion =
when {
hasMajor -> {
val next = if (v.majorVersion() == 0L) v.nextMinorVersion() else v.nextMajorVersion()
logger.quiet(
"[VersionIncrementer] MAJOR version bump: $v → $next (0.x special handling: ${v.majorVersion() == 0L})",
)
next
}
hasMinor -> {
val next = v.nextMinorVersion()
logger.quiet("[VersionIncrementer] MINOR version bump: $v → $next")
next
}
hasPatch -> {
val next = v.nextPatchVersion()
logger.quiet("[VersionIncrementer] PATCH version bump: $v → $next")
next
}
else -> {
val next = v.nextPatchVersion()
logger.quiet(
"[VersionIncrementer] Default PATCH version bump (commits present but no conventional signal): $v → $next",
)
next
}
}
newVersion
} finally {
git.close()
}
}
}
version = scmVersion.version
allprojects {
group = "io.github.flaxoos"
version = rootProject.version
}
// see: https://jreleaser.org/guide/latest/examples/maven/maven-central.html#_portal_publisher_api
jreleaser {
// Configure the project
project {
name = "${rootProject.name} - ${project.name}"
description =
"This project provides a suite of feature-rich, efficient, and highly customizable plugins for your Ktor Server or Client, crafted in Kotlin, available for multiplatform."
longDescription =
"A comprehensive collection of Ktor plugins including rate limiting, Kafka integration, circuit breaker patterns, and distributed task scheduling. Built with Kotlin Multiplatform support for JVM, Native, and JS platforms."
license = "Apache-2.0"
copyright = "Copyright (c) 2023 Ido Flax"
authors.add("Ido Flax")
maintainers.add("Ido Flax")
links {
homepage = "https://github.com/Flaxoos/extra-ktor-plugins"
documentation = "https://flaxoos.github.io/extra-ktor-plugins/"
license = "https://opensource.org/license/apache-2-0"
donation = "https://github.com/sponsors/Flaxoos"
contact = "Kotlin Slack - Ido Flax. idoflax@gmail.com"
}
inceptionYear = "2023"
}
// Sign the release
signing {
active = ALWAYS
armored = true
publicKey = jreleaserGpgPublicKey
secretKey = jreleaserGpgSecretKey
passphrase = jreleaserGpgPassphrase
}
deploy {
val stagingPath =
layout.buildDirectory
.dir("staging-deploy")
.get()
.asFile
.apply { mkdirs() }
.absolutePath
maven {
mavenCentral {
create(
"release-deploy",
closureOf<MavenCentralMavenDeployer> {
active = RELEASE
url = "https://central.sonatype.com/api/v1/publisher"
stagingRepository(stagingPath)
username = mcUsername
password = mcPassword
connectTimeout = 20
readTimeout = 60
retryDelay = 5
maxRetries = 3
},
)
}
nexus2 {
create(
"snapshot-deploy",
closureOf<Nexus2MavenDeployer> {
active = SNAPSHOT
snapshotSupported = true
closeRepository = true
releaseRepository = true
stagingRepository(stagingPath)
// maven central snapshots
snapshotUrl = "https://central.sonatype.com/repository/maven-snapshots/"
username = mcUsername
password = mcPassword
// ossrh snapshots
// snapshotUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
// username = ossrhUsername
// password = ossrhPassword
},
)
}
}
}
// Create a release in GitHub
release {
github {
enabled = true
repoOwner = "Flaxoos"
name = "extra-ktor-plugins"
tagName = "v{{projectVersion}}"
releaseName = "v{{projectVersion}}"
overwrite = true
update {
enabled = true
}
changelog {
enabled = true
formatted = ALWAYS
skipMergeCommits = false
preset = "conventional-commits"
contributors {
enabled = false
}
}
}
}
}
// Add artifact overrides for native (klib) targets after all subprojects are evaluated
gradle.projectsEvaluated {
val nativeArtifactIds =
subprojects.flatMap { subProject ->
subProject
.the<KotlinMultiplatformExtension>()
.targets
.filterIsInstance<KotlinNativeTarget>()
.map { "${subProject.name}-${it.name}" }
}
fun MavenDeployer.overrideNativeArtifacts() {
nativeArtifactIds.forEach { nativeArtifact ->
artifactOverride {
groupId.set(rootProject.group.toString())
artifactId.set(nativeArtifact)
jar.set(false)
sourceJar.set(false)
javadocJar.set(false)
verifyPom.set(false)
}
}
}
jreleaser {
deploy {
maven {
mavenCentral {
named("release-deploy") {
overrideNativeArtifacts()
}
}
nexus2 {
named("snapshot-deploy") {
overrideNativeArtifacts()
}
}
}
}
}
}
tasks.jreleaserAssemble {
dependsOn(
subprojects.flatMap { sp ->
sp.tasks.matching { it.name == "publishAllPublicationsToLocalStagingRepository" }
},
)
}
subprojects {
tasks.find { it.name == "build" }?.dependsOn(tasks.named("ktlintFormat"))
tasks.withType(Test::class) {
testLogging {
info {
testDetails()
}
}
}
extensions.findByType(GradleEnterpriseExtension::class)?.apply {
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
}
}
mkdocs {
sourcesDir = layout.projectDirectory.dir("documentation/mkdocs").toString()
python.scope = PythonExtension.Scope.USER
}
tasks.withType<org.jetbrains.dokka.gradle.DokkaCollectorTask>().configureEach {
outputDirectory.set(file("$rootDir/documentation/mkdocs/docs/dokka"))
}
fun TestLogging.testDetails() {
events = setOf(PASSED, SKIPPED, FAILED)
showStandardStreams = true
exceptionFormat = SHORT
stackTraceFilters = setOf(TestStackTraceFilter.GROOVY)
}