Hi,
I am trying to understand the correct way to create an extension that has nested types and Provider Api properties that is totally lazy.
Should nested types be wrapped in a property? If so how do we get the dsl syntax? Should kotlin receiver types be used or should just the gradle api Action interface?
// extension
open class Example @Inject constructor(objectFactory: ObjectFactory) {
val nested: Property<Nested> = objectFactory.property(Nested::class.java)
// Is this okay to configure the property?
fun nested(configure: Nested) {
nested.set(nested.get().apply(configure))
}
// or should i use the action type?
fun data(configure: Action<Nested>) {
val configured = nested.get().apply {
configure.execute(this)
}
data.set(configured)
}
}
// nested
open class Nested {
var value = "bar"
}
//build.gradle.kts
example {
// How do we do this?
nested {
value = "val"
}
}
Should nested types also have provider based members too or should the nested type just be a poko/pojo?
open class Nested {
var value = "bar"
}
// vs
open class Nested @Inject constructor(objectFactory: ObjectFactory) {
val value: Property<String> = objectFactory.property(String::class.java)
}
And my final question is around ObjectFactory.newInstance. Is the object that is created soley decorated by gradle to be extensible or is it lazy as well?
Thanks!
- Edits
I have looked at the plugin guide and the section on nested (custom data) doesn’t use the provider api.
Also the plugin guide ServerEnvironment.java
has custom setters when the Lazy Configuration Guide specifically says to avoid this. Otherwise I might just expose different member that sets the provider type.