Search code examples
androidkotlingradle-kotlin-dslkotlin-dsl

Kotlin DSL migration project gradle build


I am migrating to kotlin DSL

And this is my project level build gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I updated the file extension to -build.gradle.kts

And the file content to

plugins {
id ("com.android.application" version "7.2.2" apply false)
id ("com.android.library" version "7.2.2" apply false)
id ("org.jetbrains.kotlin.android" version "${Versions.kotlin}" apply false)
}

tasks.register("clean",Delete::class){
    delete(rootProject.buildDir)
}

I am getting this error

Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public infix fun PluginDependencySpec.version(version: String?): PluginDependencySpec defined in org.gradle.kotlin.dsl
public infix fun PluginDependencySpec.version(version: Provider<String>): PluginDependencySpec defined in org.gradle.kotlin.dsl

Solution

  • Update the plugins block as follows:

    plugins {
        id ("com.android.application") version "7.2.2" apply false
        id ("com.android.library") version "7.2.2" apply false
        id ("org.jetbrains.kotlin.android") version "${Versions.kotlin}" apply false
    }
    

    Also, I think the clean task is available by default. You do not need to create it manually.

    You can also consider migrating to Version Catalog while you are migrating. Please follow the NowInAndroid app source code for that.