https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Ahmed Riyadh

12/11/2023, 10:52 AM
Hi, does anyone know know how to setup project that uses jvm and native kotlin with different sources propely with the latest version of kotlin??
Copy code
plugins {
    alias(libs.plugins.kotlin.multiplatform)
    id("maven-publish")
}

val kotlinVersion = libs.versions.kotlin.get()
val ktorVersion = libs.versions.ktor.get()

group = "net.freshplatform"
version = libs.versions.library.get()
description =
    "A Ktor server plugin for configuring Firebase App Check easily and with simplicity. It is not affiliated with Firebase or Google and may not be suitable for production use yet."

kotlin {
    jvm()

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("io.ktor:ktor-server-core:$ktorVersion")
                implementation(libs.kotlinx.coroutines)
            }
        }
        val commonTest by getting {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")
            }
        }
        val jvmMain by getting {
            dependencies {
                implementation("io.ktor:ktor-server-core-jvm:$ktorVersion")
                implementation(libs.auth0.java.jwt)
                implementation(libs.auth0.java.jwksRsa)
            }
        }
        val jvmTest by getting {
            dependencies {
                implementation("io.ktor:ktor-server-tests-jvm:$ktorVersion")
            }
        }
//        val nativeMain by creating {
//            dependsOn(commonMain)
//        }
//        val nativeTest by creating {
//            dependsOn(nativeMain)
//        }
    }
}

repositories {
    mavenCentral()
}
m

mohamed rejeb

12/11/2023, 11:00 AM
This is not the correct way to use Kotlin/Native, you need first to set add a native target, try to add iosArm64() for example. Now you only have a jvm target that's why you can use java libraries in common main.
a

Ahmed Riyadh

12/11/2023, 11:01 AM
Thanks for the reply! I did add the following but I’m getting a build failure
m

mohamed rejeb

12/11/2023, 11:03 AM
I'm not sure what's causing this but try to add this to your gradle
a

Ahmed Riyadh

12/11/2023, 11:04 AM
Still getting the same build failure, I’m not sure either, I didn’t add any plugins other than multiplatform
m

mohamed rejeb

12/11/2023, 11:04 AM
I think it's because of this, it shouldn't be here.
Copy code
repositories {
    mavenCentral()
}
a

Ahmed Riyadh

12/11/2023, 11:05 AM
In the build.gradle.kts of the project module maybe?
m

mohamed rejeb

12/11/2023, 11:05 AM
no in the settings.gradle.kts
settings.gradle.kts
a

Ahmed Riyadh

12/11/2023, 11:05 AM
It’s already in there
m

mohamed rejeb

12/11/2023, 11:06 AM
add dependencyResolutionManagement... to settings.gralde.kts and remove repositories { mavenCentral() } from build.gralde.kts
a

Ahmed Riyadh

12/11/2023, 11:07 AM
Already tried and it gives me warrning
Now it’s working
Can’t beleive it’s because of this
I didn’t remove mavenCentral from build.gradle.kts in the module where I have this bug
m

mohamed rejeb

12/11/2023, 11:08 AM
add google and gradlePluginPortal as well you may need them in the future for some other dependencies.
👍 1
It's not needed anymore there, the configuration in settings.gradle.kts are going to be applied all over the project.
a

Ahmed Riyadh

12/11/2023, 11:09 AM
You sounds like real expert in multiplatform
m

mohamed rejeb

12/11/2023, 11:09 AM
Maybe haha
a

Ahmed Riyadh

12/11/2023, 11:09 AM
And gradle
Gradle is the only thing I don’t like about Kotlin
m

mohamed rejeb

12/11/2023, 11:11 AM
I have a video that contains some necessary informations about gradle in Kotlin Multiplatform you can check it and you will understand it more.

https://youtu.be/HpfFu2nl32s?si=PC136Y7PB7BZZRr1

a

Ahmed Riyadh

12/11/2023, 11:11 AM
Thanks