Kotlin Gradle Plugin class hierarchy

I was wondering how is it possible that the KotlinMultiplatformExtensions can be cast to ExtensionAware when none of its supertypes extends ExtensionAware. There must be some Gradle black magic here, but my muggle programming skills are not enough to figure it out.

I wondered into this question by looking at the generated Kotlin code for the K/Native cocoapods plugin:

/**
 * Retrieves the [cocoapods][org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension] extension.
 */
val org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension.`cocoapods`: org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension get() =
    (this as org.gradle.api.plugins.ExtensionAware).extensions.getByName("cocoapods") as org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension

/**
 * Configures the [cocoapods][org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension] extension.
 */
fun org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension.`cocoapods`(configure: org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.() -> Unit): Unit =
    (this as org.gradle.api.plugins.ExtensionAware).extensions.configure("cocoapods", configure)
//        🠑 some real avada kedavra high level s here!

It seems like you a are showing auto-generated runtime wrapper. It is indeed born of black magic. It is generated in runtime and cached on project synchronization. I hope that in future it will be replaced by usual extensions.

1 Like

Thanks for the insight :slight_smile:
By the way, I watched your keynote at KotlinConf2019. Great talk!