diff --git a/README.md b/README.md index 3bebada6..dc4048f4 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ To compile all classes in the project, run: docker container run --rm --user gradle --volume "$PWD":/home/gradle/app --workdir /home/gradle/app gradle:7.4.2-jdk17 gradle --no-daemon clean assemble ``` -To generate a runnable JAR of the project, run: +To generate a runnable self-contained JAR of the project, run: ```bash -docker container run --rm --user gradle --volume "$PWD":/home/gradle/app --workdir /home/gradle/app gradle:7.4.2-jdk17 gradle --no-daemon clean jar +docker container run --rm --user gradle --volume "$PWD":/home/gradle/app --workdir /home/gradle/app gradle:7.4.2-jdk17 gradle --no-daemon clean shadowJar ``` ## Tests @@ -61,9 +61,10 @@ To execute the project in development mode (with live reload), run: docker container run --rm --user gradle --volume "$PWD":/home/gradle/app --workdir /home/gradle/app gradle:7.4.2-jdk17 gradle --continuous run ``` -To execute the project in production mode, generate a runnable JAR, then run: +To execute the project in production mode, generate a runnable self-contained +JAR of the project, then run: ```bash -docker container run --rm --user gradle --volume "$PWD":/home/gradle/app --workdir /home/gradle/app gradle:7.4.2-jdk17 java -jar ./app/build/libs/app.jar +docker container run --rm --volume "$PWD"/app/build/libs/galaxy-raiders.jar:/bin/runner/galaxy-raiders.jar --workdir /bin/runner eclipse-temurin:17-jdk java -jar galaxy-raiders.jar ``` ## Other tasks diff --git a/app/build.gradle.kts b/app/build.gradle.kts index dd37257e..27ac56d4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -24,6 +24,9 @@ plugins { // Apply the Test Logger plugin to print test results in the test task. id("com.adarshr.test-logger") version "3.2.0" + // Apply the Shadow JAR Plugin to generate a standalone uber Jar. + id("com.github.johnrengelman.shadow") version "7.1.2" + // Apply the Kover plugin to better support Kotlin code coverage. id("org.jetbrains.kotlinx.kover") version "0.5.0" @@ -79,3 +82,16 @@ tasks.test { tasks.jacocoTestReport { dependsOn(tasks.test) } + +// Configure the metadata to generate an uber JAR. +tasks.shadowJar { + archiveBaseName.set("galaxy-raiders") + archiveVersion.set("") + archiveClassifier.set("") +} + +// Configure Gradle to send its stdin to the program. +// https://stackoverflow.com/questions/13172137/console-application-with-java-and-gradle +tasks.getByName("runShadow", JavaExec::class) { + standardInput = System.`in` +}