forked from uchuhimo/konf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
369 lines (325 loc) · 12.9 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
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
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import com.jfrog.bintray.gradle.BintrayExtension
import io.spring.gradle.dependencymanagement.dsl.DependenciesHandler
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import io.spring.gradle.dependencymanagement.dsl.DependencySetHandler
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.dokka.gradle.LinkMapping
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URL
import java.util.Properties
val bintrayUserProperty by extra { getPrivateProperty("bintrayUser") }
val bintrayKeyProperty by extra { getPrivateProperty("bintrayKey") }
val ossUserToken by extra { getPrivateProperty("ossUserToken") }
val ossUserPassword by extra { getPrivateProperty("ossUserPassword") }
val gpgPassphrase by extra { getPrivateProperty("gpgPassphrase") }
buildscript {
repositories {
aliyunMaven()
jcenter()
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
}
dependencies {
classpath("com.jfrog.bintray.gradle:gradle-bintray-plugin:${Versions.bintrayPlugin}")
}
}
plugins {
`build-scan`
java
jacoco
`maven-publish`
kotlin("jvm") version Versions.kotlin
kotlin("plugin.allopen") version Versions.kotlin
id("com.dorongold.task-tree") version Versions.taskTree
id("me.champeau.gradle.jmh") version Versions.jmhPlugin
id("com.diffplug.gradle.spotless") version Versions.spotless
id("io.spring.dependency-management") version Versions.dependencyManagement
id("com.github.ben-manes.versions") version Versions.dependencyUpdate
id("org.jetbrains.dokka") version Versions.dokka
}
apply(plugin = "com.jfrog.bintray")
group = "com.uchuhimo"
version = "0.13.1"
repositories {
aliyunMaven()
jcenter()
}
val wrapper by tasks.existing(Wrapper::class)
wrapper {
gradleVersion = "5.1.1"
distributionType = Wrapper.DistributionType.ALL
}
sourceSets {
register("snippet")
}
val implementation by configurations
val snippetImplementation by configurations
snippetImplementation.extendsFrom(implementation)
fun DependenciesHandler.dependencySet(group: String, version: String, action: DependencySetHandler.() -> Unit) {
dependencySet(mapOf("group" to group, "version" to version), action)
}
configure<DependencyManagementExtension> {
dependencies {
dependency("com.uchuhimo:kotlinx-bimap:${Versions.bimap}")
dependency("org.apiguardian:apiguardian-api:${Versions.apiguardian}")
dependency("com.typesafe:config:${Versions.hocon}")
dependency("org.yaml:snakeyaml:${Versions.yaml}")
dependency("com.moandjiezana.toml:toml4j:${Versions.toml4j}")
dependency("org.dom4j:dom4j:${Versions.dom4j}")
dependency("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}")
dependency("org.eclipse.jgit:org.eclipse.jgit:${Versions.jgit}")
arrayOf("stdlib", "reflect", "stdlib-jdk8").forEach { name ->
dependency(kotlin(name, Versions.kotlin))
}
arrayOf("core", "annotations", "databind").forEach { name ->
dependency(jacksonCore(name, Versions.jackson))
}
dependency(jackson("module", "kotlin", Versions.jackson))
dependency(jackson("datatype", "jsr310", Versions.jackson))
}
val testImplementation by configurations
testImplementation.withDependencies {
dependencies {
dependency(kotlin("test", Versions.kotlin))
dependency("com.natpryce:hamkrest:${Versions.hamkrest}")
dependency("org.hamcrest:hamcrest-all:${Versions.hamcrest}")
dependency("com.sparkjava:spark-core:${Versions.spark}")
dependency("org.slf4j:slf4j-simple:${Versions.slf4j}")
dependency(junit("platform", "launcher", Versions.junitPlatform))
dependency(junit("jupiter", "api", Versions.junit))
dependency(junit("jupiter", "engine", Versions.junit))
arrayOf("api", "data-driven-extension", "subject-extension", "junit-platform-engine").forEach { name ->
dependency(spek(name, Versions.spek))
}
}
}
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
implementation("org.apiguardian:apiguardian-api")
implementation("com.uchuhimo:kotlinx-bimap")
implementation("com.typesafe:config")
implementation("org.yaml:snakeyaml")
implementation("com.moandjiezana.toml:toml4j")
implementation("org.dom4j:dom4j")
implementation("org.eclipse.jgit:org.eclipse.jgit")
arrayOf("core", "annotations", "databind").forEach { name ->
implementation(jacksonCore(name))
}
implementation(jackson("module", "kotlin"))
implementation(jackson("datatype", "jsr310"))
testImplementation(kotlin("test"))
testImplementation("com.natpryce:hamkrest")
testImplementation("org.hamcrest:hamcrest-all")
testImplementation(junit("jupiter", "api"))
testImplementation("com.sparkjava:spark-core")
arrayOf("api", "data-driven-extension", "subject-extension").forEach { name ->
testImplementation(spek(name))
}
testRuntimeOnly(junit("platform", "launcher"))
testRuntimeOnly(junit("jupiter", "engine"))
testRuntimeOnly(spek("junit-platform-engine"))
testRuntimeOnly("org.slf4j:slf4j-simple")
jmhImplementation(kotlin("stdlib"))
val main by sourceSets
snippetImplementation(main.output)
}
val build by tasks.existing
val snippetClasses by tasks.existing
build { dependsOn(snippetClasses) }
java {
sourceCompatibility = Versions.java
targetCompatibility = Versions.java
}
val test by tasks.existing(Test::class)
test {
useJUnitPlatform()
testLogging.showStandardStreams = true
val properties = Properties()
properties.load(File("src/test/kotlin/com/uchuhimo/konf/source/env/env.properties").inputStream())
properties.forEach { key, value ->
environment(key as String, value)
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = Versions.java.toString()
apiVersion = Versions.kotlinApi
languageVersion = Versions.kotlinApi
}
}
allOpen {
annotation("org.openjdk.jmh.annotations.BenchmarkMode")
annotation("org.openjdk.jmh.annotations.State")
}
jmh {
//jvmArgs = ["-Djmh.separateClasspathJAR=true"]
iterations = 10 // Number of measurement iterations to do.
//benchmarkMode = ["thrpt"] // Benchmark mode. Available modes are: [Throughput/thrpt, AverageTime/avgt, SampleTime/sample, SingleShotTime/ss, All/all]
batchSize = 1
// Batch size: number of benchmark method calls per operation. (some benchmark modes can ignore this setting)
fork = 1 // How many times to forks a single benchmark. Use 0 to disable forking altogether
//operationsPerInvocation = 1 // Operations per invocation.
timeOnIteration = "1s" // Time to spend at each measurement iteration.
threads = 4 // Number of worker threads to run with.
timeout = "10s" // Timeout for benchmark iteration.
//timeUnit = "ns" // Output time unit. Available time units are: [m, s, ms, us, ns].
verbosity = "NORMAL" // Verbosity mode. Available modes are: [SILENT, NORMAL, EXTRA]
warmup = "1s" // Time to spend at each warmup iteration.
warmupBatchSize = 1 // Warmup batch size: number of benchmark method calls per operation.
//warmupForks = 0 // How many warmup forks to make for a single benchmark. 0 to disable warmup forks.
warmupIterations = 10 // Number of warmup iterations to do.
isZip64 = false // Use ZIP64 format for bigger archives
jmhVersion = Versions.jmh // Specifies JMH version
}
spotless {
java {
googleJavaFormat(Versions.googleJavaFormat)
trimTrailingWhitespace()
endWithNewline()
// licenseHeaderFile will fail with an empty line after license header,
// disable it by default
//licenseHeaderFile rootProject.file("config/spotless/apache-license-2.0.java")
}
kotlin {
ktlint(Versions.ktlint)
trimTrailingWhitespace()
endWithNewline()
// licenseHeaderFile is unstable for Kotlin
// (i.e. will remove `@file:JvmName` when formatting), disable it by default
//licenseHeaderFile rootProject.file("config/spotless/apache-license-2.0.kt")
}
}
jacoco {
toolVersion = Versions.jacoco
}
val jacocoTestReport by tasks.existing(JacocoReport::class) {
reports {
xml.isEnabled = true
html.isEnabled = true
}
}
val check by tasks.existing {
dependsOn(jacocoTestReport)
}
val dokka by tasks.existing(DokkaTask::class) {
outputFormat = "javadoc"
outputDirectory = tasks.javadoc.get().destinationDir!!.path
jdkVersion = 8
linkMapping(delegateClosureOf<LinkMapping> {
dir = project.rootDir.toPath().resolve("src/main/kotlin").toFile().path
url = "https://github.com/uchuhimo/konf/blob/v${project.version}/src/main/kotlin"
suffix = "#L"
})
externalDocumentationLink(delegateClosureOf<DokkaConfiguration.ExternalDocumentationLink.Builder> {
url = URL("http://fasterxml.github.io/jackson-databind/javadoc/${Versions.jacksonMinor}/")
})
}
val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
from(dokka)
}
val projectDescription = "A type-safe cascading configuration library for Kotlin/Java, " +
"supporting most configuration formats"
val projectGroup = project.group as String
val projectName = rootProject.name
val projectVersion = project.version as String
val projectUrl = "https://github.com/uchuhimo/konf"
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
artifact(sourcesJar.get())
artifact(javadocJar.get())
groupId = projectGroup
artifactId = projectName
version = projectVersion
pom {
name.set(rootProject.name)
description.set(projectDescription)
url.set(projectUrl)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("uchuhimo")
name.set("uchuhimo")
email.set("[email protected]")
}
}
scm {
url.set(projectUrl)
}
}
}
}
}
configure<BintrayExtension> {
user = bintrayUserProperty
key = bintrayKeyProperty
publish = true
dryRun = false
override = false
setPublications("maven")
pkg.apply {
setLabels("kotlin", "config")
publicDownloadNumbers = true
repo = "maven"
userOrg = "uchuhimo"
name = projectName
desc = projectDescription
websiteUrl = projectUrl
issueTrackerUrl = "$projectUrl/issues"
vcsUrl = "$projectUrl.git"
setLicenses("Apache-2.0")
//Optional version descriptor
version.apply {
name = projectVersion
vcsTag = "v$projectVersion"
//Optional configuration for GPG signing
gpg.apply {
sign = true //Determines whether to GPG sign the files. The default is false
passphrase = gpgPassphrase //Optional. The passphrase for GPG signing'
}
//Optional configuration for Maven Central sync of the version
mavenCentralSync.apply {
sync = true //[Default: true] Determines whether to sync the version to Maven Central.
user = ossUserToken //OSS user token: mandatory
password = ossUserPassword //OSS user password: mandatory
close = "1" //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
}
}
}
}
tasks {
val install by registering
afterEvaluate {
val publishToMavenLocal by existing
val bintrayUpload by existing
install.configure { dependsOn(publishToMavenLocal) }
bintrayUpload { dependsOn(check, install) }
}
}
val dependencyUpdates by tasks.existing(DependencyUpdatesTask::class)
dependencyUpdates {
revision = "release"
outputFormatter = "plain"
}
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
setTermsOfServiceAgree("yes")
}