When I try to run my server in a multimodule proje...
# getting-started
y
When I try to run my server in a multimodule project it always says cannot find main class. What am I doing wrong? I have the module included in settings.gradle
Please anyone i've been at this all day 😔
l
How did you declare the main function?
y
it's just a newly generated project
Copy code
fun main() {
    embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module)
        .start(wait = true)
}
l
If you click the play button next to main (assuming intellij idea), it will create a run configuration.
y
yes usually but it isn't an option in this project for some reason
l
Also, what does your build.gradle look like? That should be where you specify the main class.
y
Copy code
application {
    mainClass.set("yousef.code.ApplicationKt")

    val isDevelopment: Boolean = project.ext.has("development")
    applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}
l
Keep in mind that if main is a file-scoped function (not in a class), the class name is <package.filename>Kt. Looks like you have that.
Is the folder structure 'src/main/kotlin/yousef/code/Application.kt'?
y
yes
l
Is this project open source/on github?
y
it's newly created but I can push it
l
I don't see anything that immediately stands out as a potential issue. I'll take a closer look after work.
y
I appreciate that a lot. Thank you so much!
l
Looks like the samples set up the gradle a little differently. Have you tried a branch setting it up like they do? https://github.com/ktorio/ktor-samples/blob/main/fullstack-mpp/build.gradle
y
the issue that doesn't work with the frontend I'm using, kobweb, but that was my first approach. It has it's own jvmmain and if you add another it takes over it and generates files for it as well. So i went with multi module instead. Which also isn't working except i dont know why lol
l
You can set the base name for a source set. For example, you can do 'jvm("backend")' to get a 'backendMain' and 'backendTest'.
y
yes even with that it still did it. I told the dev about the bug
I fixed it. Had to remove the plugins from the root build.gradle and add kotlin("jvm") plugin to the backend build.grade K
Thank you again