简体   繁体   中英

How to migrate protect level build.gradle file from Gradle Groovy to Gradle Kotlin DSL

I'm trying to migrate my protect level build.gradle file from Gradle Groovy to Gradle Kotlin DSL. I've watched several tutorials but none of them clearly explain what to change the code to in the project level build.gradle file. I only got as far as renaming the file to build.gradle.kts .

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): PluginDependencySpec defined in org.gradle.kotlin.dsl

buildscript {
    ext {
        compose_version = "1.1.1"
    }
}

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

Change to:

id("com.android.application") version "7.3.1" apply false

Explanation:

version is defined as infix fun PluginDependencySpec.version(version: String) , so it can be called as id("...").version("...") or as id("...") version "..." but it cannot called on String

in your invalid code:

id( "com.android.application" /*String*/ version /*??? no String.version*/ "7.3.1" apply false )

but valid:

id( "com.android.application") /*PluginDependencySpec*/ version /*OK PluginDependencySpec.version*/ "7.3.1" apply false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM