What's the benefit of using the Gradle Property type in a Gradle plugin oppose to just using String type for example?

Viewed 183
  1. In a Gradle plugin I could define my properties as:
open class ExamplePluginExtension {

    var exampleName: String? = null

}

And accessing it in build.gradle.kts like so:

example {

    exampleName = "Lorem Ipsum"

}

Or 2. I can use the Property type of Gradle (org.gradle.api.provider.Property):

open class ExamplePluginExtension @Inject constructor(objectFactory: ObjectFactory) {

    val exampleName: Property<String> = objectFactory.property(String::class.java)

}

Accessing it in build.gradle.kts like so:

example {

    exampleName.set("Lorem Ipsum")

}

The Gradle documentation promotes the use of the Property type in Gradle Plugins, but why? The use of the Property type is quite a hassle, creates a lot of boilerplate and disables the use of nullable properties. I see many third-party libraries such as Flyway use the first option, completely ignoring the Property type.

0 Answers
Related