Idiomatic Kotlin Plugins - property.get()/set()?

The experience with the kotlin-dsl seems fragmented.

Some plugins support getter/setter to change config.

versioning {
  scm = "git"

Some use Properties

  release {
    github {
      owner.set("yschimke")
      overwrite.set(true)

Is there guidance on the idiomatic/preferred approach for a kotlin-dsl?

Some discussion in Gradle Kotlin DSL Primer, but it isn’t clear which way to build for.

Imho each and every plugin / task / extension should use properties / providers.
Only with them, you can do proper lazy evaluation and late binding without getting into ordering problems.
Did you ever write an afterEvaluate in an afterEvaluate because the first one was still evaluated too soon, resp. another afterEvaluate that came later changed the state again?

With the lazy apis (if used properly), you don’t have these problems.
It is unfortunate that there is no possibility yet to override the assignment operator in Kotlin or have an additional assignment-like operator (https://youtrack.jetbrains.com/issue/KT-20561).

Some plugin authors are concerned that the Kotlin DSL users have to use .set(...) instead of a simple assignment if they use the lazy api, but while it is not as nice as an assignment, Kotlin DSL users are just used to it by now, hoping for improvement in the future, and the benefit you get is simply undeniable. :slight_smile:

1 Like