forked from uchuhimo/konf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
277 lines (230 loc) · 7.17 KB
/
build.gradle.kts
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
/*
* Copyright (c) 2017-2024 Uchuhimo
* Copyright (c) 2024-present Nicholas Hubbard
*
* 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 specific language governing permissions and
* limitations under the License.
*/
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.util.*
// Helper function to protect private properties from being published
fun getPrivateProperty(key: String, env: String, default: String = ""): String {
val file = file("private.properties")
return if (file.exists()) {
val properties = Properties()
properties.load(file.inputStream())
properties.getProperty(key)
} else {
// Fallback if private.properties is not available
System.getenv(env).takeIf { !it.isNullOrEmpty() }
?: default
}
}
val ossUserToken by extra { getPrivateProperty("ossUserToken", "OSS_USER_TOKEN") }
val ossUserPassword by extra { getPrivateProperty("ossUserPassword", "OSS_USER_PASSWORD") }
val signPublication by extra { !System.getenv("JITPACK").toBoolean() }
plugins {
java
signing
kotlin("jvm") version "2.1.0"
kotlin("plugin.allopen") version "2.1.0"
alias(libs.plugins.dokka)
alias(libs.plugins.kover)
alias(libs.plugins.benchmark)
alias(libs.plugins.sonatype.publisher)
alias(libs.plugins.solo.publisher)
}
group = "io.github.nhubbard"
version = "2.2.1"
val projectDescription =
"A type-safe cascading configuration library for Kotlin and Java, supporting most configuration formats"
val projectUrl = "https://github.com/nhubbard/konf"
repositories {
mavenCentral()
gradlePluginPortal()
}
sourceSets {
register("snippet")
register("benchmark")
}
val snippetImplementation by configurations
snippetImplementation.extendsFrom(configurations.implementation.get())
val benchmarkImplementation by configurations
benchmarkImplementation.extendsFrom(configurations.implementation.get())
dependencies {
// Core Kotlin dependencies
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
// KotlinX Coroutines
implementation(libs.kotlinx.coroutines.core)
// Reflections
implementation(libs.reflections)
// Apache Commons Text
implementation(libs.commons.text)
// FasterXML Jackson
implementation(libs.bundles.jackson)
// Git
implementation(libs.jgit)
// Hocon
implementation(libs.hocon)
// JS
implementation(libs.bundles.graal)
// TOML
implementation(libs.toml)
// XML
implementation(libs.dom4j)
implementation(libs.jaxen)
// YAML
implementation(libs.snakeyaml)
// Core test dependencies
testImplementation(kotlin("test"))
testImplementation(libs.junit.jupiter)
testImplementation(libs.junit.params)
testRuntimeOnly(libs.junit.launcher)
testImplementation(libs.spark)
testRuntimeOnly(libs.slf4j.simple)
// Snippet implementation
snippetImplementation(sourceSets.main.get().output)
val snippet by sourceSets
testImplementation(snippet.output)
// Benchmark implementation
benchmarkImplementation(sourceSets.main.get().output)
benchmarkImplementation(libs.kotlinx.benchmark.runtime)
}
tasks.test {
useJUnitPlatform()
testLogging.apply {
showStandardStreams = true
showExceptions = true
showCauses = true
showStackTraces = true
}
systemProperties(
"org.slf4j.simpleLogger.defaultLogLevel" to "warn",
"junit.jupiter.execution.parallel.enabled" to true,
"junit.jupiter.execution.parallel.mode.default" to "concurrent",
"line.separator" to "\n"
)
environment(
"SOURCE_TEST_TYPE" to "env",
"SOURCE_CAMELCASE" to "true"
)
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
finalizedBy(tasks.koverHtmlReport)
finalizedBy(tasks.koverXmlReport)
}
tasks.compileJava {
sourceCompatibility = "11"
targetCompatibility = "11"
options.encoding = "UTF-8"
}
tasks.check {
dependsOn(tasks.koverHtmlReport)
}
tasks.dokkaHtml {
dokkaSourceSets {
configureEach {
jdkVersion.set(11)
reportUndocumented.set(false)
sourceLink {
localDirectory.set(file("./"))
remoteUrl.set(uri("https://github.com/nhubbard/konf/blob/v${project.version}/").toURL())
remoteLineSuffix.set("#L")
}
}
}
}
tasks.sourcesJar {
from(sourceSets.main.get().allSource)
}
tasks.withType<Javadoc>().all { enabled = false }
tasks.javadocJar.configure {
dependsOn(tasks.dokkaHtml)
from(tasks.dokkaHtml.get().outputDirectory)
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.named<Jar>("javadocJar") {
dependsOn(tasks.dokkaHtml)
from(tasks.dokkaHtml.get().outputDirectory)
excludes.addAll(tasks.javadoc.get().destinationDir?.listFiles()?.map { it.toString() } ?: listOf())
}
// This makes sure that Gradle is always run using JDK 21, independent of the build requirements for Konf.
// tasks.updateDaemonJvm {
// jvmVersion = JavaVersion.VERSION_21
// }
kotlin {
jvmToolchain(11)
compilerOptions {
jvmTarget = JvmTarget.JVM_11
}
sourceSets.all {
languageSettings {
languageVersion = "2.0"
}
}
}
allOpen {
annotation("org.openjdk.jmh.annotations.BenchmarkMode")
annotation("org.openjdk.jmh.annotations.State")
}
benchmark {
targets {
register("benchmark")
}
}
centralPortal {
username = ossUserToken
password = ossUserPassword
pom {
name = "konf"
description = projectDescription
url = projectUrl
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("nhubbard")
name.set("nhubbard")
email.set("[email protected]")
url.set("https://github.com/nhubbard")
}
}
scm {
url.set(projectUrl)
}
}
}
signing {
isRequired = signPublication
if (signPublication) useGpgCmd()
}
kover {
currentProject {
sources {
excludedSourceSets.addAll("benchmark", "snippet")
}
}
}
configurations.all {
resolutionStrategy.eachDependency {
// Resolve Gson vulnerability from Toml4j
if (requested.group == "com.google.code.gson" && requested.name == "gson")
useVersion("2.11.0")
// Resolve Jetty vulnerability from Spark
if (requested.group == "org.eclipse.jetty" && requested.name.matches("^jetty-(server|xml|util|http)".toRegex()))
useVersion("9.4.55.v20240627")
}
}