Hi. How do I set main class directly from commonMain? Here is my build script for the module I have ...
g
Hi. How do I set main class directly from commonMain? Here is my build script for the module I have
Copy code
plugins {
    kotlin("multiplatform")
    kotlin("plugin.serialization")
    application
}

repositories {
    mavenCentral()
}

application {
    mainClass.set("MainKt")
}

kotlin {
    jvm {
        val main by compilations.getting {
            kotlinOptions {
                jvmTarget = JavaVersion.VERSION_11.toString()
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.5")
            }
        }
        val jvmMain by getting
    }
}
There is main.kt file with main() function inside commonMain source set. It also has the run button but when I try to run it this happens
Copy code
Error: Could not find or load main class MainKt
Caused by: java.lang.ClassNotFoundException: MainKt
h
This should be correct. You can see the classes in the build folder for debugging. Or send more details.
g
It looks like this
I already had a project and this is just a new module
If there is main,kt inside jvmMain and I run it, then it works
it is as if there is some kind of limitation to commonMain
a
The
application
plugin, doesn't know how to properly play with kotlin multiplatform plugin
h
It does, you need to use
jvmTarget { withJava() }
g
Thanks, it works now.
I wish Kotlin had better errors...
wait, this fixed the application plugin task. The green button does not work
h
Hm, this is another Kotlin Idea Plugin error (KTIJ) project at youtrack
320 Views