-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
108 lines (91 loc) · 3.36 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
import groovy.lang.MissingPropertyException
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "3.2.0"
id("io.spring.dependency-management") version "1.1.4"
kotlin("jvm") version "1.9.20"
kotlin("plugin.spring") version "1.9.20"
}
val environmentVariables = readDotEnvFile()
group = "com.lightinspiration"
version = environmentVariables.getValue("JAR_VERSION")
java {
sourceCompatibility = JavaVersion.VERSION_17
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:3.2.0")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.3")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.20")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.15.3")
implementation("org.springframework.boot:spring-boot-starter-jdbc:3.2.0")
implementation("org.postgresql:postgresql:42.6.0")
implementation("org.liquibase:liquibase-core:4.25.0")
testImplementation("org.springframework.boot:spring-boot-starter-test:3.2.0")
testImplementation("org.testcontainers:postgresql:1.19.3")
testImplementation("org.mockito:mockito-core:5.7.0")
testImplementation("org.mockito.kotlin:mockito-kotlin:3.2.0")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
jvmTarget = "17"
}
}
tasks.withType<Test> {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
showExceptions = true
exceptionFormat = TestExceptionFormat.FULL
showCauses = true
showStackTraces = true
showStandardStreams = false
}
}
tasks {
val dockerComposeUp by creating(Task::class) {
description = "Builds app, spins up docker containers, and launches the API."
dependsOn(assemble)
doLast {
val command = "JAR_VERSION=$version; echo \$JAR_VERSION; docker-compose up --build --detach"
project.exec {
commandLine("sh", "-c", command)
}
}
}
val dockerComposeDown by creating(Task::class) {
description = "Pulls a running detached docker services down."
doLast {
project.exec {
commandLine("sh", "-c", "docker-compose down")
}
}
}
val dockerComposeReload by creating(Task::class) {
description = "Reload the docker services if they're already running. Includes jar rebuild."
dependsOn(dockerComposeDown)
dependsOn(dockerComposeUp)
}
}
tasks.getByName("dockerComposeUp").mustRunAfter(tasks.getByName("dockerComposeDown"))
// !--------Build Utilities---------! //
// * I tried to pull these out to a class, but when I did intellij was _not happy_ about it.
data class EnvironmentVariable(
val name: String,
val value: String
)
fun List<EnvironmentVariable>.getValue(name: String): String {
return this.firstOrNull { it.name == name }?.value
?: throw MissingPropertyException("The $name variable is missing from the .env file")
}
fun readDotEnvFile(): List<EnvironmentVariable> {
return File(".env")
.bufferedReader()
.use { it.readLines() }
.map { it.split("=") }
.map { EnvironmentVariable(it[0], it[1]) }
}