Perhaps like this? ``` presets.withType<Kotlin...
# multiplatform
p
Perhaps like this?
Copy code
presets.withType<KotlinNativeTargetPreset>().forEach { preset ->
    targetFromPreset(preset)  {
        val main by compilations.getting {
            dependencies {
                api("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.2.2")
            }
        }
    }
}
b
Im glad you added this because it clears up the question and I was going to give you completely the wrong answer. šŸ˜‚
p
šŸ™‚
b
Since you are dynamically defining targets for the native platform, are there any targets/source sets that will be used that wont be working on this dependency?
p
I donā€™t believe so. All the sources are in
commonMain
. I just want to allow it to be consumed by anything.
I hobbled this together with all the limited MPP information I could gather ^
b
Oh!
Copy code
allprojects {
  dependencies {
  
  }
}
p
Oh, Iā€™m not trying to apply it to all subprojects, sorry. What I meant to say is that I would like this library to work for any MPP target.
All the code is in
commonMain
which means itā€™s not restricted to any particular target. As such, I would like to allow library consumers to add this library as a dependency to any target they wish.
I could explicitly declare every target as it is currently set up. Or I could iterate through all presets.
b
Ok so ā€¦. where you are saying
Copy code
js {
        compilations.forEach {
            it.kotlinOptions {
                moduleKind = "umd"
                sourceMap = true
            }
        }
    }
    jvm()
    iosX64("ios") {
        binaries {
            framework("Oolong")
        }
    }
    linuxX64("linux")
    macosX64("macOS")
    mingwX64("windows")

    cocoapods {
        summary = "MVU for Kotlin Multiplatform"
        homepage = "<http://oolong-kt.org>"
    }
have it programatically define targets rather than how it currently is?
so that it has individual build targets for each platform?
Copy code
kotlin {
    presets.withType<KotlinNativeTargetPreset>().forEach {
        targetFromPreset(it) { 
            /* Configure each of the created targets */
        }
    }
}
I found this in the documentation at: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#setting-up-targets
so it looks like the code you posted should work the way you expect
Then followed with:
Copy code
targets.all {
  compilations["main"].defaultSourceSet { /* ... */ }
}
That would then provide access to all ā€œmainā€ portions of each target and allow you to add a dependency