Hey guys using kotlin dsl how can I define a varia...
# gradle
a
Hey guys using kotlin dsl how can I define a variable in root build.gradle to be used by sub module build.gradles?
with groovy I was using ext
v
You can use the same
ext
trick you used in Groovy, just with Kotlin syntax. That is to initially define the variable, you use
extra
explicitly, so
val foo by extra("bar")
, in the root project and just get it from the subproject to use it, so
val foo: String by project
But the question is whether you should do it. In almost all cases using
ext
or
extra
is a work-around and one should feel dirty when using it. Most often there is a better way, like for example adding a properly typed extension to the project instead.