Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to get properties with Kotlin-script config for Gradle

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!

like image 325
awfun Avatar asked May 16 '17 13:05

awfun


1 Answers

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

like image 135
Vyacheslav Gerasimov Avatar answered Sep 21 '22 18:09

Vyacheslav Gerasimov