almibe
07/31/2022, 6:45 PMtasks.named<JavaExec>("run") {
dependsOn(tasks.named<Jar>("jvmJar"))
classpath(tasks.named<Jar>("jvmJar"))
}
Now the simple app works when I do gradle run
, but when I depend on code from other sub-projects that are just common code when I run the application I get java.lang.NoClassDefFoundError
exceptions for the classes from the common sub-projects. (gradle check
runs fine btw)
I’m assuming this is an issue with how I have the application plugin setup, but I’m not sure what changes need to be made.mbonnin
07/31/2022, 6:47 PM"application"
plugin with "org.jetbrains.kotlin.jvm"
(and not "org.jetbrains.kotlin.multiplatform"
)mbonnin
07/31/2022, 6:47 PMmbonnin
07/31/2022, 6:48 PMalmibe
07/31/2022, 6:50 PMalmibe
07/31/2022, 7:15 PMOliver.O
08/01/2022, 1:27 PMapplication
plugin with multiplatform, but you have to add withJava()
in the kotlin.jvm()
block to work around https://youtrack.jetbrains.com/issue/KT-42683.
Actually, you don't even need the application
plugin, and without it, you can have more than one executable JVM target. For example, configuring it this way runs backendJvm
and frontendJvm
targets:
tasks {
@Suppress("UNUSED_VARIABLE")
val runBackendJvm by creating(JavaExec::class) {
group = "application"
mainClass.set("MainKt")
jvmArgs = backendJvmArgs
with(kotlin.targets["backendJvm"].compilations["main"] as KotlinJvmCompilation) {
classpath = output.allOutputs + runtimeDependencyFiles
}
}
@Suppress("UNUSED_VARIABLE")
val runFrontendJvm by creating(JavaExec::class) {
group = "application"
mainClass.set("MainKt")
with(kotlin.targets["frontendJvm"].compilations["main"] as KotlinJvmCompilation) {
classpath = output.allOutputs + runtimeDependencyFiles
}
}
}