-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle.kts
151 lines (129 loc) · 5.01 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
// Initial project setup based on https://github.com/kotlin-hands-on/jvm-js-fullstack
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
import org.asciidoctor.gradle.jvm.AsciidoctorTask
val kotlinVersion = "1.3.71"
val serializationVersion = "0.20.0"
val ktorVersion = "1.3.2"
plugins {
kotlin("multiplatform") version "1.3.71"
application //to run JVM part
kotlin("plugin.serialization") version "1.3.70"
id("org.asciidoctor.jvm.convert") version "3.1.0"
}
group = "de.oio"
version = "1.0"
repositories {
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") }
mavenCentral()
jcenter()
maven("https://kotlin.bintray.com/kotlin-js-wrappers/") // react, styled, ...
}
defaultTasks("jsBrowserProductionWebpack", "asciidoctor")
tasks.named("run") {
dependsOn(":asciidoctor")
}
kotlin {
/* Targets configuration omitted.
* To find out how to configure the targets, please follow the link:
* https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#setting-up-targets */
jvm {
withJava()
}
js {
browser {
dceTask {
keep("ktor-ktor-io.\$\$importsForInline\$\$.ktor-ktor-io.io.ktor.utils.io")
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
implementation("io.ktor:ktor-serialization:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializationVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmMain by getting {
dependencies {
implementation("io.ktor:ktor-server-core:$ktorVersion")
implementation("io.ktor:ktor-server-netty:$ktorVersion")
implementation("ch.qos.logback:logback-classic:1.2.3")
implementation(kotlin("stdlib", kotlinVersion)) // or "stdlib-jdk8"
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serializationVersion") // JVM dependency
implementation("io.ktor:ktor-websockets:$ktorVersion")
}
}
val jsMain by getting {
dependencies {
implementation(kotlin("stdlib-js"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serializationVersion")
//todo: bugfix in kx.serialization?
implementation(npm("text-encoding"))
implementation(npm("abort-controller"))
implementation("io.ktor:ktor-client-js:$ktorVersion") //include http&websockets
//todo: bugfix in ktor-client?
implementation(npm("bufferutil")) //TODO: Uncomment this and stuff breaks. WHY?
implementation(npm("utf-8-validate"))
//ktor client js json
implementation("io.ktor:ktor-client-json-js:$ktorVersion")
implementation("io.ktor:ktor-client-serialization-js:$ktorVersion")
implementation(npm("fs"))
//React, React DOM + Wrappers (chapter 3)
implementation("org.jetbrains:kotlin-react:16.13.0-pre.93-kotlin-1.3.70")
implementation("org.jetbrains:kotlin-react-dom:16.13.0-pre.93-kotlin-1.3.70")
implementation(npm("react", "16.13.0"))
implementation(npm("react-dom", "16.13.0"))
//fabric.js
implementation(npm("fabric", "3.6.3"))
}
}
}
}
application {
mainClassName = "ServerKt"
}
tasks.named<AsciidoctorTask>("asciidoctor") {
outputOptions {
backends("html5")
setOutputDir(file("$buildDir/distributions"))
}
}
tasks.getByName<KotlinWebpack>("jsBrowserProductionWebpack") {
sourceMaps = false
}
// include JS artifacts in any JAR we generate
tasks.getByName<Jar>("jvmJar") {
val taskName = if (project.hasProperty("isProduction")) {
"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")
}
}
}
}
// Alias "installDist" as "stage" for Heroku
tasks.create("stage") {
dependsOn(tasks.getByName("installDist"))
}
tasks.getByName<JavaExec>("run") {
classpath(tasks.getByName<Jar>("jvmJar")) // so that the JS artifacts generated by `jvmJar` can be found and served
}