Humphrey
08/14/2023, 9:52 AMa.b.c=Hello World
I've found this solution online but I'm wondering if there is a better way:
https://stackoverflow.com/questions/55799287/how-to-read-a-dotted-gradle-property-in-kotlin-dslMarcus Ilgner
08/14/2023, 9:56 AMrootProject
available which you can access to retrieve extra properties. For example
val pluginsDir: File by rootProject.extra
But usually the regular project
should work, too:
val ktorVersion: String by project
Is a line from the top of a one of my modules' build.gradle.kts
Adam S
08/14/2023, 9:59 AMproviders.gradleProperty("a.b.c")
1. the values are available via the Provider API, which has a lot of benefits
2. the values can have sensible defaults in the project's gradle.properties
file, but can be overridden easily, which is useful for CI/CD or on other developer's machinesHumphrey
08/14/2023, 10:03 AMMarcus Ilgner
08/14/2023, 10:03 AMgradle.properties
values. Thanks for the tip, having a dedicated mechanism (apart from shunting in a new gradle.properties
) to override in CI/CD is certainly valuable.Marcus Ilgner
08/14/2023, 10:04 AMproviders.gradleProperty("a.b.c").get()
should work?Vampire
08/14/2023, 10:06 AMhaving a dedicated mechanism (apart from shunting in a newThat has nothing to do with) to override in CI/CD is certainly valuablegradle.properties
by ...
or gradleProperty
, the same overrides work either way.Humphrey
08/14/2023, 10:07 AMVampire
08/14/2023, 10:08 AMprintln(project.findProperty("a.b.c"))
println(providers.gradleProperty("a.b.c").get())
println(project.property("a.b.c"))
Vampire
08/14/2023, 10:08 AMby ...
does not work as even with back-ticks, dots are not valid in property names.Humphrey
08/14/2023, 11:06 AM