Hello! I have a project which is multiplatform (al...
# multiplatform
v
Hello! I have a project which is multiplatform (all code is in src/commonMain). Now, I'm not actually interested in mobile or iOS, or even native maybe, and I'd like to add a JVM library to the project. I've added the dependency in gradle (`implementation("io.github.quillraven.fleksFleks1.0-RC1")`and IntelliJ has downloaded the code from mavenCentral to "external libraries". But neither IntelliJ nor gradle can build the project, which the confusing error message "Unresolved reference: com". The "com" in
import com.github.quillraven.fleks.World
is highlighted red too. So.... what do I do?
h
Since it’s a JVM specific dependency, you can’t import it in the common module.
a
@v79
Copy code
sourceSets {
    commonMain {
       // Only Multiplatform dependencies here
    }
    jvmMain {
     // Only jvm specific dependencies here
    }
}
h
And
import
should also be put into jvmMain somewhere
v
There is no jvmMain at all. There's this:
Copy code
kotlin {
    sourceSets {
        val commonMain by getting {
            kotlin.srcDir("$buildDir/generated/source/kaptKotlin/main")
            dependencies {
                implementation("com.lehaine.kiwi:kiwi:$kiwiVersion")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
                implementation("com.soywiz.korlibs.klogger:klogger:$kloggerVersion")
            }
        }

        val jvmMain by getting {
            dependencies {
implementation("io.github.quillraven.fleks:Fleks:1.0-RC1") /// THIS IS THE JVM LIB I WANT
                configurations.all { // kapt has an issue with determining the correct KMM library, so we need to help it
                    if (name.contains("kapt")) {
                        attributes.attribute(
                            org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.attribute,
                            org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm // pass in the JVM
                        )
                    }
                }
            }
        }
    }
}
I think I had better rethink. Find a multiplatform library instead (which I know doesn't exist yet...)
h
val jvmMain by getting
is there 🙂 Maybe you mean you don’t have a corresponding module in you project structure? You can create it
Do I understand correctly that you want to share the code between jvm and JavaScript?
v
I only want to run this on JVM. But the KorGE game framework I'm trying to use is multiplatform by default. I'll try asking the KorGE people...
a
In that case it should probably go under
Copy code
commonMain { 

}
Since it is a multiplatform library, then it should be imported from the
commonMain
. And then you might need to import a platform specific dependeny as well.
h
But the problem is with another library, not KorGE. The simplest way to move on from what you already have is probably to: 1. Keep what you already have in
commonMain
. 2. Add
jvmMain
next to it. 3. Put your main class there and produce the runnable artifact from there as well. In your case this structure could be minimised to only have
commonMain
and
jvmMain
(and testing modules optionally)