-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
148 lines (124 loc) · 4.32 KB
/
build.gradle.kts
File metadata and controls
148 lines (124 loc) · 4.32 KB
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
plugins {
application
kotlin("jvm") version "1.6.0"
}
group = "de.fhac.ewi"
application {
mainClass.set("io.ktor.server.netty.EngineMain")
}
repositories {
mavenLocal()
jcenter()
maven(url = "https://jitpack.io")
maven { url = uri("https://kotlin.bintray.com/ktor") }
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.20")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.20")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")
implementation("io.ktor:ktor-server-netty:1.6.1")
implementation("io.ktor:ktor-server-core:1.6.1")
implementation("io.ktor:ktor-server-host-common:1.6.1")
implementation("io.ktor:ktor-server-sessions:1.6.1")
implementation("io.ktor:ktor-gson:1.6.1")
testImplementation("io.ktor:ktor-server-tests:1.6.1")
implementation("ch.qos.logback:logback-classic:1.2.3")
implementation("io.insert-koin:koin-core:3.1.2")
implementation("io.insert-koin:koin-ktor:3.1.2")
testImplementation("io.insert-koin:koin-test:3.1.2")
implementation("com.github.doyaaaaaken:kotlin-csv-jvm:0.15.2")
implementation("com.github.EvanRupert:ExcelKt:v0.1.2")
}
kotlin.sourceSets["main"].kotlin.srcDirs("src")
kotlin.sourceSets["test"].kotlin.srcDirs("test")
sourceSets["main"].resources.srcDirs("resources")
sourceSets["test"].resources.srcDirs("testresources")
val fatJar = task("fatJar", type = Jar::class) {
// Only copy files once. 2nd attempt will be ignored without warning (Gradle 6.x) or exception (Gradle 7.x)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes["Implementation-Title"] = "Grid Optimizer - Fat"
attributes["Implementation-Version"] = project.version
attributes["Main-Class"] = "io.ktor.server.netty.EngineMain"
}
// Copy all needed dependencies for kotlin
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) {
exclude("META-INF/**")
}
// Copy frontend
from(file("src-frontend")) {
include("build/**")
}
with(tasks.jar.get() as CopySpec)
archiveFileName.set("server.jar")
}
val yarnBuild = task<Exec>("yarnBuild") {
workingDir = file("src-frontend")
if (System.getProperty("os.name").toLowerCase().contains("windows"))
commandLine("cmd.exe", "/C", "yarn.cmd run build")
else // assume *nix.
commandLine("yarn", "run", "build") // NB untested
}
var env = "production"
val buildTimestamp = System.currentTimeMillis()
tasks.processResources {
outputs.upToDateWhen { false }
filesMatching("*.conf") {
// Replace environment specific variables
when (env) {
"development" -> {
expand(
"KTOR_ENV" to "dev",
"KTOR_PORT" to "8080",
// for hot reloading (enabled)
"KTOR_MODULE" to "build",
"KTOR_AUTORELOAD" to "true",
"KTOR_DEVMODE" to "true",
// information about this build for /version route
"PROJECT_VERSION" to version,
"BUILD_TIMESTAMP" to buildTimestamp
)
}
"production" -> {
expand(
"KTOR_ENV" to "production",
"KTOR_PORT" to "80",
// for hot reloading (disabled)
"KTOR_MODULE" to "",
"KTOR_AUTORELOAD" to "false",
"KTOR_DEVMODE" to "false",
// information about this build for /version route
"PROJECT_VERSION" to version,
"BUILD_TIMESTAMP" to buildTimestamp
)
}
}
}
}
val setDev = tasks.register("setDev") {
env = "development"
}
tasks {
"run" {
dependsOn(setDev)
}
"build" {
dependsOn(fatJar)
doLast {
copy {
delete("bundle")
from(fatJar)
into(file("bundle"))
}
}
}
"fatJar" {
dependsOn(yarnBuild)
}
compileKotlin {
kotlinOptions {
freeCompilerArgs =
freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" // Opt-in option for Koin annotation of KoinComponent.
}
}
}