I'm not sure of the best channel for this discussi...
# announcements
c
I'm not sure of the best channel for this discussion, but it deals with delegates and how they are used to grab Property File values. I have seen it described very similarly before in an article that we can use a simple convention such as
Copy code
val pluginGroup: String by project
This will search for .property files for the key
pluginGroup
and return it's value as a
String
. I am impressed by that, but how the heck does this magic work? This will only return
String
values, so even if we have the following in the .properties file...
Copy code
platformDownloadSources = true
It will still only return
"true"
as a
String
. I am curious of how this mechanism works and why it is limited to only
String
and why it is limited to the specific name I have for the variable. Meaning I must name my variable the same as is in the .properties file.
v
c
To see this in usage, head over to GitHub: JetBrains/intellij-platform-plugin-template Here is gradle.properties and here is build.gradle.kts
v
Ah, you're talking about Gradle project, but well, it is similar. The Kotlin DSL seems to provide the respective methods for property delegation to work.
e
#C19FD9681 or https://gradle-community.slack.com/ might have more details
there's a few other types and extensions so that
by extra
,
by ext(defaultValue)
etc work
as for how Gradle's extensions work, that's another story altogether
c
ah, so this might be more of a Gradle specific question that uses Kotlin rather than the other way around.
v
Exactly