https://kotlinlang.org logo
#ktor
Title
# ktor
f

Fernando Sanchez (Perraco Labs)

03/13/2024, 9:36 AM
In a multi-project setup, to generate a Fat Jar, the main class in the main project is set like this:
Copy code
application {
    mainClass.set("$group.ApplicationKt")
}
But for the child sub-projects, I had to set the main class to empty:
Copy code
application {
    mainClass.set("")
}
If I don't do this, I encounter an exception when running the buildFatJar task:
Copy code
Execution failed for task ':kcrud-employment:shadowJar'.
Error while evaluating property 'mainClassName' of task ':kcrud-employment:shadowJar'.
Cannot query the value of extension 'application' property 'mainClass' because it has no value available.
Is it expected behavior to explicitly set the mainClass to empty for sub-projects? I assumed this would be implicitly detected by the Gradle task.
d

Dominik Sandjaja

03/13/2024, 10:39 AM
What gradle plugins do you define for your subprojects? It might be that you have them defined as application as well, which you most likely don’t want.
f

Fernando Sanchez (Perraco Labs)

03/13/2024, 1:31 PM
Found the issue. In the main project I have:
Copy code
plugins {
    application
    alias(libs.plugins.kotlin.jvm)
    alias(libs.plugins.ktor)
    alias(libs.plugins.kotlin.serialization)
    alias(libs.plugins.graphql.expedia)
}
And the sub-projects I had:
Copy code
plugins {
    alias(libs.plugins.kotlin.jvm)
    alias(libs.plugins.ktor)
    alias(libs.plugins.kotlin.serialization)
    alias(libs.plugins.graphql.expedia)
}
Removing
alias(libs.plugins.ktor)
in the sub-projects solves the issue. I'm a bit confused about why.