how can I share a variable between `buildscript` b...
# gradle
c
how can I share a variable between
buildscript
block and other places? I want to declare
kotlinVersion
once and use it throughout the build file. In Groovy Gradle it would've been
buildscript { ext.kotlinVersion = "" }
But in kotlin-dsl
buildscript { val kotlinVersion by extra { "" } }
does not work, in
dependencies
block it is not resolved.
n
In Gradle Kotlin DSL you could do it like this:
Copy code
buildscript {
    extra["kotlin-ver"] = "1.1.50"

    // ...
    dependencies {
        classpath(kotlin(module = "gradle-plugin", version = "${extra["kotlin-ver"]}"))
    }
}

val KOTLIN_VER = "${extra["kotlin-ver"]}"
👍 1
j
Hi, I struggled with the same issue. extra not being resolved in by extra delegation expressions. Just from curiosity, the delegation works for other stuff but not for dependency declaration, right? I also note another delegation used quite extensively - by tasks. Does this delegation also suffer from some restrictions? Thank you in advance. Antonel