This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
141 lines (118 loc) · 4.04 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
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
val ktorVersion = "2.0.2"
val kotlinWrappersVersion = "1.0.0-pre.547"
fun kotlinw(target: String) = "org.jetbrains.kotlin-wrappers:kotlin-$target"
fun ktor(target: String) = "io.ktor:ktor-$target:$ktorVersion"
fun ktorClient(target: String) = ktor("client-$target")
fun ktorServer(target: String) = ktor("server-$target")
fun kotlinx(target: String) = "org.jetbrains.kotlinx:kotlinx-$target"
plugins {
kotlin("multiplatform") version "1.8.20"
application
kotlin("plugin.serialization") version "1.8.20"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("io.ktor.plugin") version "2.3.0"
}
group = "me.elevator"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
}
kotlin {
jvm {
jvmToolchain(17)
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js(IR) {
binaries.executable()
browser {
testTask {
enabled = false
}
commonWebpackConfig {
cssSupport {
enabled.set(false)
}
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlinx("serialization-json:1.5.0"))
implementation(kotlinx("coroutines-core:1.7.0"))
implementation ("com.benasher44:uuid:0.7.0")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting {
dependencies {
implementation(ktor("serialization"))
implementation(ktorServer("content-negotiation"))
implementation(ktor("serialization-kotlinx-json"))
implementation(ktorServer("cors"))
implementation(ktorServer("compression"))
implementation(ktorServer("core-jvm"))
implementation(ktorServer("netty"))
implementation("ch.qos.logback:logback-classic:1.4.6")
}
}
val jvmTest by getting
val jsMain by getting {
dependencies {
implementation(ktorClient("js"))
implementation(ktorClient("content-negotiation"))
implementation(ktor("serialization-kotlinx-json"))
implementation(project.dependencies.enforcedPlatform(kotlinw("wrappers-bom:$kotlinWrappersVersion")))
implementation(kotlinw("react"))
implementation(kotlinw("react-dom"))
implementation(kotlinw("react-dom-legacy"))
implementation(npm("core-js", "3.16.2"))
implementation(kotlinw("ring-ui"))
implementation(kotlinw("emotion"))
}
}
val jsTest by getting
}
}
application {
mainClass.set("me.elevator.application.ServerKt")
}
tasks.getByName<JavaExec>("run") {
dependsOn(tasks.named<Jar>("jvmJar"))
classpath(tasks.named<Jar>("jvmJar"))
}
tasks.getByName<Jar>("jvmJar") {
val taskName = if (project.hasProperty("isProduction")
|| project.gradle.startParameter.taskNames.contains("installDist")
) {
"jsBrowserProductionWebpack"
} else {
"jsBrowserDevelopmentWebpack"
}
val webpackTask = tasks.getByName<KotlinWebpack>(taskName)
dependsOn(webpackTask) // make sure JS gets compiled first
from(File(webpackTask.destinationDirectory, webpackTask.outputFileName)) // bring output file along into the JAR
}
distributions {
main {
contents {
from("$buildDir/libs") {
rename("${rootProject.name}-jvm", rootProject.name)
into("lib")
}
}
}
}
tasks.register<Copy>("copyJs"){
from("build/distributions/${rootProject.name}.js")
to("src/commonMain/resources/${rootProject.name}.js")
}