I was trying out the Kotlin DSL, specifically type-safe accessors. I wanted to test how accessors are generated for extensions on various elements. I add all extensions from a plugin, because they have to be added when the plugins
block is evaluated.
In my plugin, I created a dummy type for the elements to store in a container:
// in plugin
interface Element extends Named, ExtensionAware {
}
I add a container to the project as an extension:
// in plugin
def containerOfElement = project.container(Element)
project.extensions.add('projectExtensionContainerOfElement', containerOfElement)
This leads to a type-safe accessor for it being generated:
// in build script
println(project.projectExtensionContainerOfElement)
Type safe accessors are also added to elements in the container:
// in plugin
def foo = project.objects.newInstance(Element, 'foo')
containerOfElement.add(foo)
// in build script
println(project.projectExtensionContainerOfElement.foo)
I also add an extension to the foo
element:
// in plugin
foo.extensions.add('someStringProperty', project.objects.property(String))
According to the Kotlin DSL primer, I expected also a type-safe accessor for the property:
// in build script
println(project.projectExtensionContainerOfElement.foo.someStringProperty)
This unfortunately doesn’t work. I get a compile error.
Am I doing something wrong? Am I misunderstanding the DSL primer?