From ce7d231c9a7e50a9c0720e72056ff44d58fcf608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Sun, 7 Nov 2021 13:53:41 +0100 Subject: [PATCH] Make fat jar a thing, modularize app. --- README.md | 9 +++++++++ build.gradle.kts | 18 ++++++++++++++++++ .../de/pheerai/buzzer/data/InlineClasses.kt | 1 - src/main/kotlin/module-info.java | 12 ++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/module-info.java diff --git a/README.md b/README.md index dcdcf66..4f0dc99 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,16 @@ A simple buzzer implementation using web technologies. ## 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. +Alternatively, you can create the artifact using `gradlew shadowJar`. The output will be written to `/build/libs/`. Then run it using `java -jar `. + After it successfully launched, you have access to two clients. ### 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: +* 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 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. diff --git a/build.gradle.kts b/build.gradle.kts index 634e301..7b5884e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + val ktor_version: String by project val kotlin_version: String by project val logback_version: String by project @@ -6,12 +8,15 @@ val kotlinx_html_version: String by project plugins { application kotlin("jvm") version "1.5.31" + id("com.github.johnrengelman.shadow") version "7.1.0" } group = "de.pheerai.buzzer" version = "0.0.1" + application { mainClass.set("de.pheerai.buzzer.ApplicationKt") + applicationDefaultJvmArgs = listOf("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED", "-Dio.netty.tryReflectionSetAccessible=true") } repositories { @@ -28,3 +33,16 @@ dependencies { testImplementation("io.ktor:ktor-server-tests:$ktor_version") testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlin_version") } + +tasks { + withType().configureEach { + sourceCompatibility = JavaVersion.VERSION_11.toString() + targetCompatibility = JavaVersion.VERSION_11.toString() + } + + withType().configureEach { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_11.toString() + } + } +} diff --git a/src/main/kotlin/de/pheerai/buzzer/data/InlineClasses.kt b/src/main/kotlin/de/pheerai/buzzer/data/InlineClasses.kt index 6d4b2bd..c4c4b8a 100644 --- a/src/main/kotlin/de/pheerai/buzzer/data/InlineClasses.kt +++ b/src/main/kotlin/de/pheerai/buzzer/data/InlineClasses.kt @@ -2,7 +2,6 @@ package de.pheerai.buzzer.data import io.ktor.http.cio.websocket.* - @JvmInline value class PlayerSocket(val session: WebSocketSession) @JvmInline diff --git a/src/main/kotlin/module-info.java b/src/main/kotlin/module-info.java new file mode 100644 index 0000000..872b09b --- /dev/null +++ b/src/main/kotlin/module-info.java @@ -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; +}