How to distribute a Kotlin CLI application?

Viewed 183

I've built a small bot in Kotlin.

It's finished and I can run it from my developer tools. I am using the application plugin to attempt distribution but I keep failing.

./gradlew run runs the bot as expected.

I was looking for something like ./gradlew installDist and then just running installationDir/bin/App (similar to Ktor apps) and running the app. But it just exits successfully with no output when I should see a lot of logging output.

What am I doing wrong?

// gradle.build.kts
import org.jetbrains.kotlin.gradle.plugin.statistics.ReportStatisticsToElasticSearch.url
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.5.31"
    kotlin("plugin.serialization") version "1.5.31"
    application
}

group = "me.nanospicer"
version = "1.0"

repositories {
    mavenCentral()
    maven {
        url = uri("https://jitpack.io")
    }
}


tasks.withType<KotlinCompile>() {
    kotlinOptions.jvmTarget = "1.8"
}

application {
    mainClass.set("MainKt")
}

val ktor_version="1.6.5"
dependencies {
    implementation("ch.qos.logback:logback-classic:1.2.7")
    implementation("io.ktor:ktor-client-core:$ktor_version")
    implementation("io.ktor:ktor-client-cio:$ktor_version")
    implementation("io.ktor:ktor-client-serialization:$ktor_version")
    implementation("io.ktor:ktor-client-logging:$ktor_version")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1")
}
1 Answers
  • Good news: The setup posted on my question works flawlessly.
  • Bad news: My code didn't.

I had a file that didn't exist on the server and a part of the code was returning null so the app would quit without any output because it wouldn't do anything due to the file being non-existent.

Related