gradle-mkdocs-plugin icon indicating copy to clipboard operation
gradle-mkdocs-plugin copied to clipboard

extras lazy evaluation in Gradle Kotlin DSL

Open sargunv opened this issue 3 months ago • 2 comments

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.

sargunv avatar Oct 01 '25 06:10 sargunv

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).

xvik avatar Oct 01 '25 07:10 xvik

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()
      )
    }
  )
}

sargunv avatar Oct 14 '25 05:10 sargunv