I have a property in gradle.properties
:
answer = 42
Which is used in build.gradle
:
println "answer is ${answer}"
Now I want to replace Groovy with Kotlin-script for Gradle configuring. How to access properties in a proper way? What I'm doing now in build.gradle.kts
is:
fun property(name: String) = properties[name] as String
println("answer is " + property("answer"))
Which does not seem to be very convenient. Thanks!
Try delegated property, like this:
val answer by project
println("answer is $answer")
There is example in gradle script kotlin repo https://github.com/gradle/gradle-script-kotlin/tree/master/samples/project-properties
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With