I build my ktor project with this command: gradle shadowJar --no-daemon, but it doesn't add my resources folder to the fat jar.
My build.gradle is this:
val ktor_version = "2.0.2"
val kotlin_version = "1.6.10"
val logback_version = "1.2.11"
plugins {
application
kotlin("jvm") version "1.6.10"
id("com.github.johnrengelman.shadow") version "7.1.2"
}
group = "com.cstcompany"
version = "0.0.1"
application {
mainClass.set("com.cstcompany.ApplicationKt")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}
repositories {
mavenCentral()
maven { url = uri("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")
//FreeMarker
implementation("io.ktor:ktor-server-freemarker:$ktor_version")
}
In IntelliJ my code works, but when I deploy it to a fat jar it doesn't find my files in my resources folder.
In order to have the same url that work for both Jar or in local, the url (or path) needs to be a relative path from the repository root.
..meaning, the location of your file or folder from your
srcfolder.Whatever it is, in order for your JAR file to find it, the url must be a relative path from the repository root.
Now you get the drill, and luckily for Intellij Idea users, you can get the correct path with
a right-click on the folder or file -> copy Path/Reference.. -> Path From Repository Root (this is it)Last, paste it and do your thing.