Hi , I am currently migrating scripts from groovy ...
# community-support
a
Hi , I am currently migrating scripts from groovy -> kotlin . I have 2 gradle files build.gradle.kts and config.gradle There is a Closure defined in config.gradle as an extra property :
Copy code
config.gradle

ext.applyBuildConfigs = { baseExtension -> .... }

baseExtension is the android extension.
I am using it in build.gradle.kts like :
Copy code
android {
    val applyBuildConfigs: Closure<Any?> by extra
    applyBuildConfigs(android)
}
This works as expected I wanted to convert config.gradle to kts , i tried this approach :
Copy code
config.gradle.kts

val applyConfigs: (com.android.build.gradle.internal.dsl.BaseAppModuleExtension) -> Unit by extra({ baseExtension ->
    ....
})
but I get the error :
Unresolved reference: android
I can get rid of this error by adding Android Gradle Plugin to the classpath of config.gradle.kts
Copy code
config.gradle.kts

buildscript {
    repositories {
        mavenCentral()
        google()
    }

    dependencies {
        classpath (libs.agp)
    }
}

val applyConfigs: (com.android.build.gradle.internal.dsl.BaseAppModuleExtension) -> Unit by extra({ baseExtension ->

})
I am not sure if this is the correct way but it makes the error go away (IDE still shows error but IDE shown error for all non build.gradle.kts files) But now when I call
applyConfigs(android)
I get the error
class com.android.build.gradle.internal.dsl.BaseAppModuleExtension_Decorated cannot be cast to class com.android.build.gradle.internal.dsl.BaseAppModuleExtension
What would be the correct way to achieve this ? I do not want to create custom plugins for this right now .
t
I'm assuming this is a script plugin applied from
apply(from = "config.gradle")
; then migrate it to a precompiled script plugin in
buildSrc
or an included build, and possibly rework your plugin management (add AGP as a dependency to
buildSrc
) to avoid those classloader issues.
👍 1