-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
131 lines (109 loc) · 3.68 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
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.10"
application
id("maven-publish")
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
id("io.gitlab.arturbosch.detekt") version "1.20.0"
}
group = "com.okp4"
description = "A Kafka Streams Processor"
application {
mainClass.set("com.okp4.processor.cosmos.MainKt")
}
fun prepareVersion(): String {
val digits = (project.property("project.version") as String).split(".")
if (digits.size != 3) {
throw GradleException("Wrong 'project.version' specified in properties, expects format 'x.y.z'")
}
return digits.map { it.toInt() }
.let {
it.takeIf { it[2] == 0 }?.subList(0, 2) ?: it
}.let {
it.takeIf { !project.hasProperty("release") }?.mapIndexed { i, d ->
if (i == 1) d + 1 else d
} ?: it
}.joinToString(".") + project.hasProperty("release").let { if (it) "" else "-SNAPSHOT" }
}
afterEvaluate {
project.version = prepareVersion()
}
repositories {
mavenCentral()
}
dependencies {
val kafkaStreamVersion = "3.1.0"
api("org.apache.kafka:kafka-streams:$kafkaStreamVersion")
val slf4jVersion = "1.7.36"
api("org.slf4j:slf4j-api:$slf4jVersion")
api("org.slf4j:slf4j-log4j12:$slf4jVersion")
val micrometerVersion = "1.9.2"
api("io.micrometer:micrometer-core:$micrometerVersion")
api("io.micrometer:micrometer-registry-prometheus:$micrometerVersion")
testImplementation(kotlin("test"))
val kotestVersion = "5.3.1"
testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
testImplementation("io.kotest:kotest-property:$kotestVersion")
testImplementation("io.kotest:kotest-framework-datatest:$kotestVersion")
testImplementation("org.apache.kafka:kafka-streams-test-utils:$kafkaStreamVersion")
}
tasks {
val fatJar = register<Jar>("fatJar") {
dependsOn.addAll(listOf("compileJava", "compileKotlin", "processResources"))
archiveClassifier.set("standalone")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest { attributes(mapOf("Main-Class" to application.mainClass)) }
val sourcesMain = sourceSets.main.get()
val contents = configurations.runtimeClasspath.get()
.map { if (it.isDirectory) it else zipTree(it) } +
sourcesMain.output
from(contents)
}
build {
dependsOn(fatJar)
}
}
tasks.register("lint") {
dependsOn.addAll(listOf("ktlintCheck", "detekt"))
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
testLogging {
events("PASSED", "SKIPPED", "FAILED")
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.apply {
jvmTarget = "11"
allWarningsAsErrors = true
}
}
tasks.named<KotlinCompile>("compileTestKotlin") {
kotlinOptions.apply {
jvmTarget = "11"
allWarningsAsErrors = false
}
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
artifact(tasks["fatJar"])
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/okp4/${project.name}")
credentials {
username = project.property("maven.credentials.username") as String
password = project.property("maven.credentials.password") as String
}
}
}
}