extras lazy evaluation in Gradle Kotlin DSL
The documentation for variables says to use lazy evaluation syntax for certain properties:
mkdocs {
extras = [
'version': "${-> project.version}",
'something': 'something else'
]
}
Is there a recommended equivalent for Gradle .kts files? I tried project.provider { project.version } but the map needs a Serializeable.
I'm not working with kotlin but, after a quick googling, I found lazy variables:
val versionValue: String by lazy {
project.version
}
mkdocs {
extras = [
'version': "$versionValue",
'something': 'something else'
]
}
I don't know if this will work, but the best I can suggest.
Generally, I like the idea with providers. I will see how to add providers support (or something like) some time later (busy right now with other release).
That doesn't work; the lazy block is evaluated as soon as versionValue is read (it's essentially just delegating the getter and memoizing the result).
I think I've found a way to use a provider though:
tasks.withType<MkdocsTask>().configureEach {
extras.assign(
provider {
mapOf(
"project_version" to project.version.toString()
)
}
)
}