I'm working on my multiplatform project and added ktor based backend module as part of it as i wanted to share my common code with this backend module i've added it to dependencies
implementation(project(":shared"))
But there seems to be an issue with sharing code for jvm target(which ktor backend is) I've found a workaround to have my project got this dependency resolved by marking this backend submodule as a multiplatform itself, but now as I build it and start to run I'm getting this error
Error: Could not find or load main class com.owlsoft.backend.ServerKt
My whole backend ktor build.gradle.kts
plugins {
application
kotlin("multiplatform")
id("kotlinx-serialization")
}
kotlin {
jvm {
withJava()
}
}
application {
@Suppress("DEPRECATION")
mainClassName.set("com.owlsoft.backend.ServerKt")
}
dependencies {
implementation(Libs.Coroutines.core)
implementation(Libs.KtorServer.core)
implementation(Libs.KtorServer.netty)
implementation(Libs.KtorServer.serialization)
implementation(Libs.KtorServer.websockets)
implementation(Libs.kotlinSerialization) // JVM dependency
implementation("ch.qos.logback:logback-classic:1.2.3")
implementation(project(":shared"))
testImplementation(Libs.KtorServer.test)
}
tasks.register("stage") {
dependsOn("installDist")
}
I'm mostly trying to share some models and business logic I've only made backend module with ktor in it multiplatform to fix issue with it's not being able to pick up shared module changes.
I faced the same problem in the same scenario. I fixed this way:
Open Module Settings
backend
module is inside your project, not as a separate module above. Remove the separate module if exists (code will remain the same).backend
:src - jvmMain - kotlin - Server.kt
I think the root cause is that I added
backend
module with Android Studio and the project structure was broken somehow.