This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
141 lines (123 loc) · 4.08 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
val version: String by project
val ktor_version: String by project
val kotlin_version: String by project
val logback_version: String by project
val koin_version: String by project
val pi4j_version: String by project
plugins {
application
kotlin("jvm") version "1.6.21"
}
group = "com.adclock"
application {
mainClassName = "io.ktor.server.netty.EngineMain"
}
repositories {
mavenLocal()
jcenter()
maven { url = uri("https://kotlin.bintray.com/ktor") }
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version")
implementation("io.ktor:ktor-server-netty:$ktor_version")
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.ktor:ktor-server-core:$ktor_version")
implementation("io.ktor:ktor-server-host-common:$ktor_version")
implementation("io.ktor:ktor-gson:$ktor_version")
implementation("org.koin:koin-core:$koin_version")
implementation("org.koin:koin-ktor:$koin_version")
implementation("com.pi4j:pi4j-core:$pi4j_version")
testImplementation("io.ktor:ktor-server-tests:$ktor_version")
}
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) {
manifest {
attributes["Implementation-Title"] = "ADClock Server - Fat"
attributes["Implementation-Version"] = project.version
attributes["Main-Class"] = "io.ktor.server.netty.EngineMain"
}
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
from(sourceSets["main"].resources)
with(tasks.jar.get() as CopySpec)
archiveFileName.set("server.jar")
}
val npmBuild = task<Exec>("npmBuild") {
workingDir = file("src-frontend")
if (System.getProperty("os.name").toLowerCase().contains("windows"))
commandLine("cmd.exe", "/C", "npm.cmd run build")
else // assume *nix.
commandLine("npm", "run", "build") // NB untested
}
val copyDistFolder = tasks.register<Copy>("copyDistFolder") {
delete("resources/dist")
from(file("src-frontend/dist"))
into(file("resources/dist"))
}
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
"KTOR_MODULE" to "build",
"KTOR_AUTORELOAD" to "true",
"KTOR_DEVMODE" to "true",
// for /version route
"PROJECT_VERSION" to version,
"BUILD_TIMESTAMP" to buildTimestamp
)
}
"production" -> {
expand(
"KTOR_ENV" to "production",
"KTOR_PORT" to "80",
// For hot reloading
"KTOR_MODULE" to "",
"KTOR_AUTORELOAD" to "false",
"KTOR_DEVMODE" to "false",
// 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(copyDistFolder)
}
"copyDistFolder" {
// TODO dependsOn(npmBuild)
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" // Opt-in option for Koin annotation of KoinComponent.
}
}
}