0

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.

So I have modules like this

  • 1
    Ktor server is JVM-only. Could you please describe what code do you want to share across different platforms? – Aleksei Tirman Apr 22 '21 at 12:23
  • I've edited issue a little bit. So I'm trying to share a "shared" module which contains common models and some business logic it works well for android app and ios but not so good for the "backend" module which is JVM based module and when I'm trying to do ```implement(project("shared")) in it it just doesn't see any models from my shared module So I've tried to make backend multiplatform as well and it worked well as shared models now properly visible from inside of backend module But I can not run the server in this backend module now . It fails with the error described above – Андрій Пугач Apr 22 '21 at 22:36
  • I recommend using this sample project https://github.com/ktorio/ktor-samples/tree/main/fullstack-mpp as an example to solve your problem. – Aleksei Tirman Apr 26 '21 at 12:34

0 Answers0