Make fat jar a thing, modularize app.

This commit is contained in:
Oliver Rümpelein 2021-11-07 13:53:41 +01:00
parent b5d1525184
commit ce7d231c9a
4 changed files with 39 additions and 1 deletions

View file

@ -4,8 +4,16 @@ A simple buzzer implementation using web technologies.
## Usage ## Usage
### Preconditions
You need a JDK, version 11 upwards.
### Build
Until artifact storage is provided, start the service using `gradlew run` from within the project directory. Until artifact storage is provided, start the service using `gradlew run` from within the project directory.
Alternatively, you can create the artifact using `gradlew shadowJar`. The output will be written to `<projectDir>/build/libs/`. Then run it using `java -jar <JarFile>`.
After it successfully launched, you have access to two clients. After it successfully launched, you have access to two clients.
### Player-Client ### Player-Client
@ -35,6 +43,7 @@ Your surface consists of three parts. After a game has started, and some player
This project contains a weird mixture of technologies that I wanted to play around with: This project contains a weird mixture of technologies that I wanted to play around with:
* Currently, there is no check for uniqueness of player names, and the name is used as identifier (that's the simplest way to be consistent across reconnects). Make sure each player uses a different name!
* The server-portion is based on the [ktor][ktor] framework, a rather lightweight, code-configured web servicing library. * The server-portion is based on the [ktor][ktor] framework, a rather lightweight, code-configured web servicing library.
* The clients' HTML files are created on the fly using the domain specific HTML language provided by [kotlinx-html][kotlinxhtml]. * The clients' HTML files are created on the fly using the domain specific HTML language provided by [kotlinx-html][kotlinxhtml].
* Javascript and data binding in the clients is achieved by embedding [alpine-js][alpinejs], in conjunction with a few extension functions to integrate it into kotlinx-html. * Javascript and data binding in the clients is achieved by embedding [alpine-js][alpinejs], in conjunction with a few extension functions to integrate it into kotlinx-html.

View file

@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val ktor_version: String by project val ktor_version: String by project
val kotlin_version: String by project val kotlin_version: String by project
val logback_version: String by project val logback_version: String by project
@ -6,12 +8,15 @@ val kotlinx_html_version: String by project
plugins { plugins {
application application
kotlin("jvm") version "1.5.31" kotlin("jvm") version "1.5.31"
id("com.github.johnrengelman.shadow") version "7.1.0"
} }
group = "de.pheerai.buzzer" group = "de.pheerai.buzzer"
version = "0.0.1" version = "0.0.1"
application { application {
mainClass.set("de.pheerai.buzzer.ApplicationKt") mainClass.set("de.pheerai.buzzer.ApplicationKt")
applicationDefaultJvmArgs = listOf("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED", "-Dio.netty.tryReflectionSetAccessible=true")
} }
repositories { repositories {
@ -28,3 +33,16 @@ dependencies {
testImplementation("io.ktor:ktor-server-tests:$ktor_version") testImplementation("io.ktor:ktor-server-tests:$ktor_version")
testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlin_version") testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlin_version")
} }
tasks {
withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = JavaVersion.VERSION_11.toString()
}
withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}
}

View file

@ -2,7 +2,6 @@ package de.pheerai.buzzer.data
import io.ktor.http.cio.websocket.* import io.ktor.http.cio.websocket.*
@JvmInline @JvmInline
value class PlayerSocket(val session: WebSocketSession) value class PlayerSocket(val session: WebSocketSession)
@JvmInline @JvmInline

View file

@ -0,0 +1,12 @@
module buzzer {
requires ktor.server.host.common.jvm;
requires ktor.server.netty.jvm;
requires ktor.server.core.jvm;
requires ktor.websockets.jvm;
requires ktor.html.builder.jvm;
requires org.slf4j;
requires ktor.http.cio.jvm;
requires kotlinx.coroutines.core.jvm;
requires kotlin.stdlib;
requires kotlinx.html.jvm;
}