-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.gradle.kts
181 lines (161 loc) · 5.21 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
@file:OptIn(ExperimentalKotlinGradlePluginApi::class)
import net.kyori.indra.git.IndraGitExtension
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
plugins {
alias(libs.plugins.indra.git)
alias(libs.plugins.jib)
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.spotless)
}
val javaTarget = 21
val entryPoint = "io.ktor.server.netty.EngineMain"
java {
val targetVersion = JavaVersion.toVersion(javaTarget)
sourceCompatibility = targetVersion
targetCompatibility = targetVersion
if (JavaVersion.current() < targetVersion) {
toolchain { languageVersion.set(JavaLanguageVersion.of(javaTarget)) }
kotlin.jvmToolchain(javaTarget)
}
}
repositories {
mavenCentral()
maven(url = "https://oss.sonatype.org/content/repositories/snapshots/") {
name = "sonatype-oss-snapshots"
mavenContent {
snapshotsOnly()
}
}
}
spotless {
fun com.diffplug.gradle.spotless.FormatExtension.setup() {
endWithNewline()
trimTrailingWhitespace()
}
kotlin {
setup()
ktlint(libs.versions.ktlint.get())
}
kotlinGradle {
setup()
ktlint(libs.versions.ktlint.get())
}
}
kotlin {
explicitApi()
jvm {
withJava()
mainRun {
mainClass = entryPoint
}
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.fromTarget("$javaTarget")
freeCompilerArgs.add("-Xjdk-release=$javaTarget")
}
}
js {
browser {
}
compilerOptions {
target = "es2015"
}
binaries.executable()
}
sourceSets {
configureEach {
languageSettings {
optIn("kotlin.RequiresOptIn")
}
}
named("commonMain") {
dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.kotlinx.html)
}
}
named("jvmMain") {
dependencies {
implementation(libs.bundles.ktor.server)
implementation(libs.bundles.ktor.client)
implementation(libs.ktor.network)
implementation(libs.adventure.minimessage)
implementation(libs.adventure.text.serializer.gson)
implementation(libs.adventure.text.serializer.legacy)
implementation(libs.cache4k)
implementation(libs.logback.classic)
}
}
}
}
jib {
to.image = "ghcr.io/kyoripowered/adventure-webui/webui"
from {
image = "azul/zulu-openjdk-alpine:$javaTarget-jre"
platforms {
// We can only build multi-arch images when pushing to a registry, not when building locally
val requestedTasks = gradle.startParameter.taskNames
if ("jibBuildTar" in requestedTasks || "jibDockerBuild" in requestedTasks) {
platform {
// todo: better logic
architecture =
when (System.getProperty("os.arch")) {
"aarch64" -> "arm64"
else -> "amd64"
}
os = "linux"
}
} else {
platform {
architecture = "amd64"
os = "linux"
}
platform {
architecture = "arm64"
os = "linux"
}
}
}
}
container {
setMainClass(entryPoint)
labels.put(
"org.opencontainers.image.description",
"""A Web UI for working with Adventure components.
Built with Adventure ${libs.versions.adventure.get()}, from webui commit ${indraGit.commit()?.name ?: "<unknown>"}""",
)
}
}
tasks {
val webpackTask =
if (isDevelopment()) {
"jsBrowserDevelopmentWebpack"
} else {
"jsBrowserProductionWebpack"
}.let { taskName ->
named<KotlinWebpack>(taskName)
}
named<Jar>("jvmJar") {
rootProject.indraGit.applyVcsInformationToManifest(manifest)
}
named<AbstractCopyTask>("jvmProcessResources") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from(webpackTask.flatMap { it.mainOutputFile })
filesMatching("application.conf") {
expand(
"jsScriptFile" to "${rootProject.name}.js",
"miniMessageVersion" to libs.adventure.minimessage.get().versionConstraint.requiredVersion,
"commitHash" to rootProject.extensions.getByType<IndraGitExtension>().commit()?.name.orEmpty(),
)
}
}
// the kotlin plugin creates this task super late for some reason?
configureEach {
if (name == "jvmRun" && isDevelopment()) {
(this as JavaExec).jvmArgs("-Dio.ktor.development=true", "-DwebuiLogLevel=trace")
}
}
}
/** Checks if the development property is set. */
fun isDevelopment(): Boolean = project.hasProperty("isDevelopment")