https://kotlinlang.org logo
Title
c

Czar

09/25/2017, 2:06 PM
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

napperley

09/26/2017, 4:42 AM
In Gradle Kotlin DSL you could do it like this:
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

jtonic

10/14/2017, 10:36 AM
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