Hi everyone, I just created a new project with Kot...
# gradle
t
Hi everyone, I just created a new project with Kotlin Gradle scripts. I have a property defined in
gradle.properties
:
Copy code
com.foo.myproperty=bar
What is the idiomatic way to read that property from scripts ? The property delegate syntax
val myProperty by project
makes it mandatory to declare a variable with the same name as the property. Moreover, it seems that there is no
settings.property("com.foo.myproperty")
function.
c
the delegate is the way to go unless you have variable names incompatible with kotlin variable naming. in settings it's just
by settings
instead of
by project
if your names are not compatible with kotlin var naming, then:
extra["your.prop.name"]
in both project and settings, if you're nesting it you could spefity the receiver explicitely, just in case:
settings.extra["..."]
g
I tend to use
findProperty("com.foo.myproperty") as? String
j
can you do a delegate for a property with dots? that's most of them
t
for properties with dots, I've ended up just using
project.properties["name.of.the.property"].toString()