I want to build an extension that has a nested property inside.
I’ve tried to use lazy properties and latest guidelines but it doesn’t work, so I think I’m missing something.
In the current form, the script crashes on evaluation, with message:
> Failed to apply plugin class 'MyPlugin'.
> Could not create an instance of type MyExtension.
> Could not generate a decorated class for type MyExtension.
> Cannot have abstract method MyExtension.getDevTarget().
I suspect the problem is in the line
abstract DevTarget getDevTarget()
Maybe the field is not managed? The correct syntax is different?
Gradle version is 6.9.1, java is 8, language is Groovy.
The simplified code is below:
apply plugin: MyPlugin
abstract class DevTarget {
abstract Property<String> getUrl()
abstract Property<String> getUser()
}
abstract class MyExtension {
abstract DevTarget getDevTarget()
}
class MyPlugin implements Plugin<Project> {
void apply(Project project) {
project.extensions.create("myx", MyExtension)
}
}
// test config
myx {
devTarget {
url = 'dev url'
user = 'dev user'
}
}
task show {
doLast {
println "DevTarget: ${myx.devTarget.url.get()}"
}
}