MohammadBaqer
MohammadBaqer

Reputation: 1415

ktor execute jar file

I want make a jar file from my ktor project.

here is my main function

import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
    routing {
        get("/") {
            call.respondText("Hello World!")
        }
      }
   }.start(wait = true)
}

and here is my build.gradle

plugins {
id 'application'
id 'org.jetbrains.kotlin.jvm' version '1.6.20'
}

group "com.example"
version "0.0.1"
mainClassName = "com.example.ApplicationKt"

def isDevelopment = project.ext.has("development")
applicationDefaultJvmArgs = ["-Dio.ktor.development=$isDevelopment"]

application {
mainClass.set("io.ktor.server.netty.EngineMain")
}

repositories {
mavenCentral()
maven { url "https://maven.pkg.jetbrains.space/public/p/ktor/eap" }
}

dependencies {
implementation "io.ktor:ktor-server-core-jvm:$ktor_version"
implementation "io.ktor:ktor-server-netty-jvm:$ktor_version"
implementation "ch.qos.logback:logback-classic:$logback_version"
testImplementation "io.ktor:ktor-server-tests-jvm:$ktor_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}

and here is my settings.gradle

rootProject.name = "ktor-sample"

when I try to run ./gradlew :ktor-sample:installDist I get this error

Upvotes: 0

Views: 402

Answers (2)

João Garrido
João Garrido

Reputation: 69

When I need to create a .jar of a ktor project I usually add this to the build.gradle.kts


val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
    jvmTarget = "1.8"
}

val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
    jvmTarget = "1.8"
}

and after running the following on terminal

gradlew stage

a .jar is then created in the build/libs/project.jar.

Upvotes: 1

Aleksei Tirman
Aleksei Tirman

Reputation: 6989

I guess you don't have a subproject named ktor-sample so just run ./gradlew installDist.

Upvotes: 2

Related Questions