Search code examples
kotlingradlew

error in build.gradle.kts script using extra property


below is a small (build.gradle.kts) script which gives at line 9 (the classpath line) the error : Cannot get property 'kotlinVersion' on extra properties extension as it does not exist

buildscript {
    extra["kotlinVersion"] = "1.2.70"

    repositories {
        jcenter()
    }

    dependencies {
      classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${extra["kotlinVersion"]}")
    }
}

I do not understand why this error occur.


Solution

  • This works for me:

    buildscript {
        extra["kotlin_version"] = "1.3.61"
    
        repositories {
            google()
            jcenter()
    
        }
        dependencies {
            classpath("com.android.tools.build:gradle:3.5.3")
            classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${extra["kotlin_version"]}")
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
    
        }
    }