-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle.kts
193 lines (170 loc) · 5.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
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
import com.bmuschko.gradle.docker.tasks.container.DockerRemoveContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStartContainer
import com.bmuschko.gradle.docker.tasks.image.DockerPullImage
import io.gitlab.arturbosch.detekt.Detekt
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
val kotlinVersion = "1.9.23"
kotlin("multiplatform") version kotlinVersion
id("com.bmuschko.docker-remote-api") version "9.4.0"
id("io.gitlab.arturbosch.detekt").version("1.23.6")
id("convention.publication")
}
group = "io.github.moreirasantos"
version = "1.2.1"
repositories {
mavenCentral()
}
val chosenTargets = (properties["targets"] as? String)?.split(",")
?: listOf("macosArm64", "macosX64", "linuxArm64", "linuxX64", "jvm")
kotlin {
// Tiers are in accordance with <https://kotlinlang.org/docs/native-target-support.html>
fun KotlinNativeTarget.libpq(filename: String) {
val main by compilations.getting {
cinterops {
val libpq by registering {
defFile(project.file("src/nativeInterop/cinterop/$filename"))
}
}
}
}
val availableTargets = mapOf(
Pair("macosArm64") { macosArm64 { libpq("libpqMacosArm64.def") } },
Pair("macosX64") { macosX64 { libpq("libpqMacosX64.def") } },
Pair("linuxArm64") { linuxArm64 { libpq("libpqLinuxArm64.def") } },
Pair("linuxX64") { linuxX64 { libpq("libpqLinuxX64.def") } },
Pair("jvm") { jvm() },
)
chosenTargets.forEach {
println("Enabling target $it")
availableTargets[it]?.invoke()
}
/*
// Currently unsupported
// Tier 3
mingwX64("mingwX64")
*/
// android, ios, watchos, tvos, js will never(?) be supported
applyDefaultHierarchyTemplate()
sourceSets {
configureEach {
languageSettings.progressiveMode = true
}
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
implementation("io.github.oshai:kotlin-logging:6.0.3")
}
}
if (chosenTargets.contains("jvm")) {
val jvmMain by getting {
dependencies {
implementation("org.springframework.data:spring-data-r2dbc:3.2.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.8.0")
implementation("org.postgresql:r2dbc-postgresql:1.0.4.RELEASE")
implementation("io.r2dbc:r2dbc-pool:1.0.1.RELEASE")
}
}
val jvmTest by getting {
dependencies {
implementation("org.postgresql:r2dbc-postgresql:1.0.4.RELEASE")
implementation("org.jetbrains.kotlin:kotlin-test:1.9.23")
}
}
}
}
}
val pull by tasks.registering(DockerPullImage::class) {
image.set("postgres:15-alpine")
}
val create by tasks.registering(DockerCreateContainer::class) {
dependsOn(pull)
containerName.set("test")
imageId.set("postgres:15-alpine")
this.envVars.set(
mapOf(
"POSTGRES_PASSWORD" to "postgres"
)
)
hostConfig.portBindings.set(listOf("5678:5432"))
/*
Doesn't work
healthCheck.cmd.set(listOf("pg_isready -U postgres"))
healthCheck.interval.set(1000000000)
healthCheck.timeout.set(1000000000)
healthCheck.retries.set(3)
healthCheck.startPeriod.set(100000000000000)
*/
}
val start by tasks.registering(DockerStartContainer::class) {
dependsOn(create)
containerId.set(create.get().containerId)
doLast {
// Sleeping while healthcheck doesn't work
Thread.sleep(2000)
}
}
val remove by tasks.registering(DockerRemoveContainer::class) {
dependsOn(create)
dependsOn(start)
containerId.set(create.get().containerId)
force.set(true)
}
tasks {
val dependencies: Task.() -> Unit = {
dependsOn(start)
finalizedBy(remove)
}
chosenTargets.forEach {
findByName("${it}Test")?.dependencies()
?: register("${it}Test")(dependencies)
}
}
tasks.withType<Test> {
testLogging {
events("PASSED", "FAILED", "SKIPPED")
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
showStackTraces = true
}
}
detekt {
buildUponDefaultConfig = true // preconfigure defaults
config.setFrom("$projectDir/config/detekt.yml")
}
tasks.withType<Detekt>().configureEach {
setSource(files(project.projectDir))
exclude("**/*.kts")
exclude("**/build/**")
reports {
jvmTarget = "21"
html.required.set(true) // observe findings in your browser with structure and code snippets
sarif.required.set(true) // standardized SARIF format (https://sarifweb.azurewebsites.net/)
}
}
tasks {
// Explicit dependency because gradle says it's implicit and fails build
val dependencies: Task.() -> Unit = {
listOf(
"signJvmPublication",
"signLinuxX64Publication",
"signLinuxArm64Publication",
"signMacosArm64Publication",
"signMacosX64Publication",
"signKotlinMultiplatformPublication"
).forEach { dependsOn(it) }
}
listOf(
"publishMacosArm64PublicationToSonatypeRepository",
"publishMacosX64PublicationToSonatypeRepository",
"publishJvmPublicationToSonatypeRepository",
"publishKotlinMultiplatformPublicationToSonatypeRepository",
"publishLinuxX64PublicationToSonatypeRepository"
).forEach { findByName(it)?.dependencies() }
}
java {
targetCompatibility = JavaVersion.VERSION_21
}