error in build.gradle.kts script using extra property
Asked Answered
C

2

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.

Chaparro answered 13/2, 2020 at 10:1 Comment(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...Mayramays
B
4

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

    }
}
Bastien answered 15/2, 2020 at 14:5 Comment(8)
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 513msChaparro
I moved your script to an other directory and it does work ! I do not understand why these different behaviorsChaparro
In what directory was it? And what is the new one?Bastien
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 ?Chaparro
@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?Mayramays
@EmileAchadde the problem was obviously something else... so either put that as an answer yourself... or delete the question altogether, because otherwise it doesn't make any sense...Mayramays
I deleted this last question : I could not reproduce the issue. (The question reappeared ...)Chaparro
I do not understand why extra variables need to be defined inside the buildscript block. Is that a bug ?Chaparro
T
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"]}")
            }
        }
Trug answered 7/6, 2020 at 14:44 Comment(0)
B
4

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

    }
}
Bastien answered 15/2, 2020 at 14:5 Comment(8)
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 513msChaparro
I moved your script to an other directory and it does work ! I do not understand why these different behaviorsChaparro
In what directory was it? And what is the new one?Bastien
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 ?Chaparro
@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?Mayramays
@EmileAchadde the problem was obviously something else... so either put that as an answer yourself... or delete the question altogether, because otherwise it doesn't make any sense...Mayramays
I deleted this last question : I could not reproduce the issue. (The question reappeared ...)Chaparro
I do not understand why extra variables need to be defined inside the buildscript block. Is that a bug ?Chaparro

© 2022 - 2024 — McMap. All rights reserved.