-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
199 lines (166 loc) · 6.47 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
import com.avast.gradle.dockercompose.ComposeExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.ConnectException
import java.net.URI
import kotlin.math.max
plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("org.jetbrains.dokka")
id("com.avast.gradle.docker-compose")
id("maven-publish")
}
repositories {
mavenCentral()
maven(url = "https://jitpack.io") {
content {
includeGroup("com.github.jillesvangurp")
}
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
dependencies {
implementation(KotlinX.coroutines.jdk8)
implementation(KotlinX.coroutines.slf4j)
implementation(KotlinX.serialization.json)
implementation(KotlinX.datetime)
implementation("io.github.microutils:kotlin-logging:_")
implementation("com.github.jasync-sql:jasync-postgresql:_")
testImplementation("org.junit.jupiter:junit-jupiter:_")
testImplementation(Testing.kotest.assertions.core)
testImplementation("org.slf4j:slf4j-api:_")
testImplementation("org.slf4j:jcl-over-slf4j:_")
testImplementation("org.slf4j:log4j-over-slf4j:_")
testImplementation("org.slf4j:jul-to-slf4j:_")
testImplementation("org.apache.logging.log4j:log4j-to-slf4j:_") // es seems to insist on log4j2
testImplementation("ch.qos.logback:logback-classic:_")
testImplementation("com.github.jillesvangurp:kotlin4example:_")
}
configure<ComposeExtension> {
buildAdditionalArgs = listOf("--force-rm")
stopContainers = true
removeContainers = true
useComposeFiles = listOf("docker-compose.yml")
setProjectName("pg-docstore")
listOf("/usr/bin/docker","/usr/local/bin/docker").firstOrNull {
File(it).exists()
}?.let { docker ->
// works around an issue where the docker
// command is not found
// falls back to the default, which may work on
// some platforms
dockerExecutable.set(docker)
}
}
val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}
val dokkaJar = tasks.register<Jar>("dokkaJar") {
from(tasks["dokkaHtml"])
dependsOn(tasks["dokkaHtml"])
archiveClassifier.set("javadoc")
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
artifact(sourcesJar.get())
artifact(dokkaJar.get())
}
}
repositories {
maven {
// change to point to your repo, e.g. http://my.org/repo
url = uri("gcs://mvn-public-tryformation/releases")
name = "FormationPublic"
}
}
}
tasks.withType<Test> {
failFast = false
notCompatibleWithConfigurationCache("db isUp check is not compatible")
val isUp = try {
URI.create("http://localhost:5432").toURL().openConnection().connect()
true
} catch(e: ConnectException) {
project.logger.lifecycle("CONNECTION REFUSED ${e::class.simpleName} ${e.message}")
e.message != "Connection refused"
}
if(!isUp) {
project.logger.lifecycle("Compose hooks")
// if it's already running just use the existing instance
dependsOn("composeUp")
finalizedBy("composeDown")
} else {
project.logger.lifecycle("DB is already running, no compose hooks")
}
useJUnitPlatform {
}
systemProperties["junit.jupiter.execution.parallel.enabled"] = "true"
// executes test classes concurrently
systemProperties["junit.jupiter.execution.parallel.mode.default"] = "concurrent"
// executes tests inside a class concurrently
systemProperties["junit.jupiter.execution.parallel.mode.classes.default"] = "concurrent"
systemProperties["junit.jupiter.execution.parallel.config.strategy"] = "fixed"
// make sure we don't starve es and enrichment of cpu cores
// note, our eventually blocks cause threads to spend a lot of time delaying
val threads = max(3,Runtime.getRuntime().availableProcessors()-2)
println("running tests with $threads threads on a machine with ${Runtime.getRuntime().availableProcessors()} CPUs and ${Runtime.getRuntime().maxMemory()/1024/1024} MB memory")
// val threads = 3
systemProperties["junit.jupiter.execution.parallel.config.fixed.parallelism"]=threads
systemProperties["junit.jupiter.execution.parallel.config.fixed.max-pool-size"]=threads
systemProperties["junit.jupiter.testclass.order.default"] = "org.junit.jupiter.api.ClassOrderer\$ClassName"
// systemProperties["junit.jupiter.testclass.order.random.seed"] = "42"
// works around an issue with the ktor client and redis client needing more than 64 threads in our tests.
// systemProperties["kotlinx.coroutines.io.parallelism"] = "200"
// junit test runner in gradle ignores @ActiveProfile, go figure
systemProperty("spring.profiles.active", "test")
testLogging.exceptionFormat = TestExceptionFormat.FULL
testLogging.events = setOf(
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT
)
addTestListener(object : TestListener {
val failures = mutableListOf<String>()
override fun beforeSuite(desc: TestDescriptor) {
}
override fun afterSuite(desc: TestDescriptor, result: TestResult) {
}
override fun beforeTest(desc: TestDescriptor) {
}
override fun afterTest(desc: TestDescriptor, result: TestResult) {
if (result.resultType == TestResult.ResultType.FAILURE) {
val report =
"""
TESTFAILURE ${desc.className} - ${desc.name}
${
result.exception?.let { e ->
"""
${e::class.simpleName} ${e.message}
""".trimIndent()
}
}
-----------------
""".trimIndent()
failures.add(report)
}
}
})
}
// gradle dokkaGfm
tasks.withType<DokkaTask>().configureEach {
notCompatibleWithConfigurationCache("https://github.com/Kotlin/dokka/issues/2231")
}