Reputation: 1415
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
What went wrong: Project 'ktor-sample' not found in root project 'ktor-sample'.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Upvotes: 0
Views: 402
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
Reputation: 6989
I guess you don't have a subproject named ktor-sample
so just run ./gradlew installDist
.
Upvotes: 2