https://kotlinlang.org logo
Title
s

Smith

01/05/2020, 2:47 PM
I have a multiproject gradle setup with Kotlin DSL. In my master build.gradle.kts I have:
val someVersion: String by extra("1.2.3")
However, in childproj/build.gradle.kts:
val someVersion: String by extra
does not work, saying “Cannot get non-null extra property ‘someVersion’” What’s the appropriate way to do variable inheritance?
c

Czar

01/05/2020, 5:16 PM
extra is scoped. In the child project you can do either of these:
val someVersion: String by project
(
project
delegate inherits properties from parent project, including
extra
) or direct access if you want to prevent a clash with something like `gradle.properties`:
val someVersion: String by rootProject.extra
n

Nicholas Bilyk

01/06/2020, 2:55 PM
If you don't need the dynamic initialization
extra("1.2.3")
any properties you put in your gradle.properties will be available to all projects gradle.properties
someVersion=1.2.3