9

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.

1
  • please add your actual solution as an answer and don't accept answers, that are basically the same to what you wrote in your question. This doesn't help anyone else that may have the same problem as you... Commented Feb 18, 2020 at 9:43

2 Answers 2

5

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"]}")
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

4
+50

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

    }
}

8 Comments

gradlew build gives : FAILURE: Build failed with an exception. * Where: Build file '/home/achadde/sources/kotlin-minichain/build.gradle.kts' line: 11 * What went wrong: Cannot get property 'kotlin_version' on extra properties extension as it does not exist * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at help.gradle.org BUILD FAILED in 513ms
I moved your script to an other directory and it does work ! I do not understand why these different behaviors
In what directory was it? And what is the new one?
They are two parallel directories with the same internal structure : the good one : /home/achadde/sources/ipfs-api-kotlin the bad one : /home/achadde/sources/kotlin-minichain Do you have an idea ?
@EmileAchadde It took me a while to understand what is the difference of the answer in regards to the question... while I do not want Max Aves to lose any points... how can you accept an answer, that doesn't differ in what you have in your question???? Or did I miss something?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.