'How to set global variables in gradle.kts?
My app uses several gradle.kts scripts. I want to set one variable which would be global for everyone.
object Versions{
val kotlin_version = "1.3.60-eap-25"
}
but it is not resolved:
classpath ("org.jetbrains.kotlin:kotlin-gradle-plugin:$Versions.kotlin_version")
Solution 1:[1]
Declared them in gradle.properties
file:
kotlin_version = 1.3.60-eap-25
And use it everywhere by findProperty("kotlin_version ")
Solution 2:[2]
in project level gradle the
ext.kotlin_version = '1.3.61'
Should just be:
val kotlinVersion by rootProject.extra { "1.3.61" }
And then you can access it by doing this:
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${rootProject.extra.get("kotlinVersion")}")
in your app module
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | elect |
Solution 2 | John |