Emile Achadde
Emile Achadde

Reputation: 1815

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.

Upvotes: 9

Views: 2236

Answers (2)

Roman Savelev
Roman Savelev

Reputation: 51

You must use "project.extra[...]" instead of "extra[...]"

    buildscript {
            extra["kotlin_version"] = "1.3.72"

            repositories {
                jcenter()
            }

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

Upvotes: 5

Maksym V.
Maksym V.

Reputation: 2937

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()

    }
}

Upvotes: 4

Related Questions