Caleb Cushing
10/02/2024, 6:31 PMProperty::convention and Provider::orElse since Property extends/implement Provider?ephemient
10/02/2024, 6:38 PMconvention modifies the Property, orElse returns a new ProviderCaleb Cushing
10/02/2024, 6:39 PMCaleb Cushing
10/02/2024, 6:39 PMephemient
10/02/2024, 6:42 PMinterface MyExtension {
@get:Input
val property: Property<String>
}
class MyPlugin : Plugin<Project> {
override fun apply(project: Project) {
val extension = project.objects.newInstance<MyExtension>()
project.extensions.create("my", extension)
}
}
my.property.orElse("foo")
my.property.get() // error
my.property.convention("foo")
my.property.get() // "foo"ephemient
10/02/2024, 6:43 PMorElse on the caller's side since even with a convention, a property can get unsetephemient
10/02/2024, 6:43 PMCaleb Cushing
10/02/2024, 6:46 PMCaleb Cushing
10/02/2024, 6:46 PMCaleb Cushing
10/02/2024, 6:47 PMVampire
10/02/2024, 7:53 PMorElse you say "when I here at this place want a value but the provider is empty, then use that value". With convention you say "if anyone wants to get the value of this property and it was not customized or was but then set to null, then that customer should get this value, no matter which consumer it is".
But yes, even with a convention value one could set to an unset provider which makes the property unset even if a convention is set.
Sometimes this even is intended and important.
For example if some task has a property for a toolchain tool and a property for an executable and the tool is used if set, otherwise the executable, but the toolchain tool has a convention. Then you can set it to an empty provider, so that the executable property is used.
So which to use, or maybe even both heavily depends on the individual use-case and intended behavior.