All of my Kotlin multiplatform build scripts starts with this boilerplate which declares the supported platforms and also sets the framework name for the iOS-specific platforms:
kotlin {
android()
listOf(iosX64(), iosArm64(), iosSimulatorArm64()).forEach {
it.binaries.framework {
baseName = iosFrameworkName
}
}
}
I want to pull this code into a precompiled script plugin so that only iosFrameworkName
is set by the build script. But how do you do this? I tried to set it using a Property in an extension in precompiled plugin, but that doesn’t work because it immediately tries to get the property while applying my plugin before I get a chance to set it.
I think what I want is a way to defer the kotlin
call until after the build script applies my plugin, so the build script would look like
plugins {
id("com.myproject.kmm")
}
kmm {
iosFrameworkName = "MyFramework"
}
where kmm
is a custom DSL call that runs the above kotlin
call. But I can’t find any documentation about how to do this. All of the docs I’ve read only tell you how to do stuff like get/set properties and define tasks/extensions. But in this case I would need to call Project.kotlin
. If I try to import that into a plugin it gets it from import gradle.kotlin.dsl.accessors._91c3ea59e5d2e7adad42047b60d6d606.kotlin
which makes me think I’m doing something wrong.