Is it possible to import `org.jetbrains.kotlin.gra...
# gradle
r
Is it possible to import
org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
class to my buildSrc module? I have written an extension function for configuring my ios target in my multiplatform project, but since it is also multi module project I have that function repeated in each module’s gradle script - would be nice to be able to move that to one place.
v
Why shouldn't it be possible?
r
It cannot resolve this class, I guess I should add some dependency to make it available
If I write:
Copy code
val a: org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension? = null
it gives me an error:
Unresolved reference: kotlin
This is my build.gradle.kts of buildSrc:
Copy code
plugins {
    `kotlin-dsl`
}

repositories {
    jcenter()
}
DependencyHandlerScope
is resolved correctly but not
KotlinMultiplatformExtension
v
Because the first is part of the Gradle built-in Kotlin DSL, the second not
You can see here: https://search.maven.org/search?q=fc:org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension that it is part of the kotlin-gradle-plugin, so it should work if you add that to your dependencies
r
yeah that was my idea to add
Copy code
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10")
to dependencies inside buildSrc/build.gradle.kts
Adding that results with an error: * Exception is: java.lang.NoClassDefFoundError: com/android/build/gradle/BaseExtension at org.jetbrains.kotlin.gradle.plugin.AbstractAndroidProjectHandler.configureTarget(KotlinPlugin.kt:765) at org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPlugin$Companion.applyToTarget(KotlinPlugin.kt:727) at org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPlugin.apply(KotlinPlugin.kt:689) at org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPlugin.apply(KotlinPlugin.kt:678)
Copy code
at org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper.apply(KotlinPluginWrapper.kt:102)
changing
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10")
to
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10")
resolves the problem
thanks a lot 🙂
119 Views