-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
237 lines (204 loc) · 7.76 KB
/
build.gradle.kts
File metadata and controls
237 lines (204 loc) · 7.76 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
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.SourcesJar
import java.net.URI
import nl.littlerobots.vcu.plugin.versionSelector
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
group = "dev.hermannm"
version = "0.10.1"
mavenPublishing {
coordinates(group.toString(), artifactId = "devlog-kotlin", version.toString())
pom {
name = "devlog-kotlin"
description =
"Structured logging library for Kotlin, that aims to provide a developer-friendly API with minimal runtime overhead."
url = "https://devlog-kotlin.hermannm.dev"
inceptionYear = "2024"
licenses {
license {
name = "MIT"
url = "https://github.com/hermannm/devlog-kotlin/blob/main/LICENSE"
distribution = "repo"
}
}
developers {
developer {
id = "hermannm"
name = "Hermann Mørkrid"
url = "https://hermannm.dev"
}
}
scm {
url = "https://github.com/hermannm/devlog-kotlin"
connection = "scm:git:https://github.com/hermannm/devlog-kotlin.git"
developerConnection = "scm:git:https://github.com/hermannm/devlog-kotlin.git"
}
}
configure(
KotlinMultiplatform(
javadocJar = JavadocJar.Dokka(taskName = "dokkaGeneratePublicationJavadoc"),
sourcesJar = SourcesJar.Sources(),
),
)
signAllPublications()
publishToMavenCentral(automaticRelease = false)
}
// Dependency versions are declared in Gradle version catalog (./gradle/libs.versions.toml)
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.kotlinxSerialization)
alias(libs.plugins.spotless)
alias(libs.plugins.gradleMavenPublish)
alias(libs.plugins.binaryCompatibilityValidator)
alias(libs.plugins.dokka)
alias(libs.plugins.dokkaJavadoc)
alias(libs.plugins.versionCatalogUpdate)
signing
}
subprojects {
apply(plugin = rootProject.libs.plugins.kotlinJvm.get().pluginId)
apply(plugin = rootProject.libs.plugins.kotlinxSerialization.get().pluginId)
apply(plugin = rootProject.libs.plugins.spotless.get().pluginId)
repositories { mavenCentral() }
}
kotlin {
sourceSets {
commonMain {
dependencies {
implementation(libs.kotlinxSerialization)
implementation(libs.kotlinReflect)
}
jvm {
compilerOptions {
jvmTarget = JvmTarget.JVM_11
// We set this in addition to jvmTarget, as it gives us some additional verification that
// we don't use more modern JDK features:
// https://kotlinlang.org/docs/compiler-reference.html#xjdk-release-version
freeCompilerArgs.add("-Xjdk-release=11")
}
}
}
commonTest {
dependencies {
implementation(libs.kotlinTest)
implementation(libs.kotest)
}
}
jvmMain.dependencies {
implementation(libs.slf4j)
implementation(libs.jackson)
// Optional dependency: This library works for any SLF4J logger implementation, but makes some
// optimizations for Logback. If the user chooses Logback as their logger implementation, we
// can apply these optimizations, but if they don't, then we don't want to load Logback, as
// that can interfere with other SLF4J logger implementations on the classpath.
compileOnly(libs.logback)
// Optional dependency - we only need this if the user:
// - Has chosen Logback as their logger implementation
// - Uses logstash-logback-encoder for encoding logs as JSON
// - Wants to use our JsonContextFieldWriter
compileOnly(libs.logstashLogbackEncoder)
}
jvmTest.dependencies {
runtimeOnly(libs.logback)
runtimeOnly(libs.logstashLogbackEncoder)
}
}
jvm {
// To use JUnit 5 rather than JUnit 4:
// https://kotlinlang.org/docs/gradle-configure-project.html#jvm-variants-of-kotlin-test
testRuns["test"].executionTask.configure { useJUnitPlatform() }
}
compilerOptions {
// Expected-actual classes are in beta (though almost stable):
// https://kotlinlang.org/docs/multiplatform-expect-actual.html#expected-and-actual-classes
freeCompilerArgs.add("-Xexpect-actual-classes")
}
// Require explicit public modifiers, to avoid accidentally publishing internal APIs
explicitApi()
// Workaround to support single-target multiplatform projects in Dokka:
// https://github.com/Kotlin/dokka/issues/3122
if (
// To match both dokkaGeneratePublicationHtml and :dokkaGeneratePublicationHtml, both valid
gradle.startParameter.taskNames.any { taskName ->
taskName.endsWith("dokkaGeneratePublicationHtml")
}
) {
linuxX64()
}
}
repositories { mavenCentral() }
spotless {
kotlin {
target("src/**/*.kt", "integration-tests/**/*.kt")
// Check for new versions here: https://github.com/facebook/ktfmt
ktfmt("0.61")
toggleOffOn()
}
}
// Use GPG agent for signing Maven Central publication
signing { useGpgCmd() }
tasks.withType<Jar> {
// Copy license into META-INF in output jars
metaInf.with(copySpec().from("${project.rootDir}/LICENSE"))
// Add Automatic-Module-Name to META-INF/MANIFEST for better Java module interop:
// https://dev.java/learn/modules/automatic-module/
manifest.attributes("Automatic-Module-Name" to "dev.hermannm.devlog")
}
// Provides `publishing/publishAllPublicationsToLocalTestRepository` task to check publication
// output before we publish to Maven Central
publishing {
repositories {
maven {
name = "LocalTest"
url = uri(layout.buildDirectory.dir("testPublication"))
}
}
}
// We only want to use the binary compatibility validator on the main library, not our
// integration test sub-projects
apiValidation { ignoredProjects.addAll(subprojects.map { it.name }) }
dokka {
dokkaSourceSets.configureEach {
// Embeds this Markdown file on the module documentation page
includes.from("gradle/dokka/module-docs.md")
sourceLink {
// Links to the Git tag for the current version of the library
remoteUrl = URI("https://github.com/hermannm/devlog-kotlin/tree/v${rootProject.version}/src")
remoteLineSuffix = "#L"
localDirectory = projectDir.resolve("src")
}
externalDocumentationLinks.register("kotlinx.serialization") {
url = URI("https://kotlinlang.org/api/kotlinx.serialization/")
packageListUrl = URI("https://kotlinlang.org/api/kotlinx.serialization/package-list")
}
// Require docstrings for all public APIs
reportUndocumented = true
// Don't include deprecated APIs in generated site
skipDeprecated = true
}
pluginsConfiguration.html {
homepageLink = "https://github.com/hermannm/devlog-kotlin"
footerMessage =
"""Developed by Hermann Mørkrid (<a href="https://hermannm.dev" target="_blank" style="color: inherit; text-decoration: underline">https://hermannm.dev</a>). Licensed under <a href="https://github.com/hermannm/devlog-kotlin/blob/main/LICENSE" target="_blank" style="color: inherit; text-decoration: underline">MIT</a>."""
// Overrides the default homepage link icon with a GitHub icon
customAssets.from("gradle/dokka/github-icon.svg")
customStyleSheets.from("gradle/dokka/custom-styles.css")
}
dokkaPublications.html { failOnWarning = true }
}
versionCatalogUpdate {
sortByKey = false // We order dependencies by importance in `libs.versions.toml`
versionSelector { module ->
val invalidVersionRegexes =
listOf(
Regex("(?i).*Alpha(?:-?\\d+)?"),
Regex("(?i).*a(?:-?\\d+)?"),
Regex("(?i).*Beta(?:-?\\d+)?"),
Regex("(?i).*-B(?:-?\\d+)?"),
Regex("(?i).*RC(?:-?\\d+)?"),
Regex("(?i).*CR(?:-?\\d+)?"),
Regex("(?i).*M(?:-?\\d+)?"),
)
return@versionSelector invalidVersionRegexes.none { it.matches(module.candidate.version) }
}
}