2
我正在开发一个定制的摇篮插件,我想定义的配置闭合(插件扩展名)是这样的:嵌套对象
myplugin {
property1 'value'
property2 {
a1 'hello'
a2 'bye'
}
}
我有这个类:
public class MyPluginExtension { //root extension
String property1;
Property2 peroperty2;
//getters and setters
}
public class Property2 {
String a1;
String a2;
//getters and setters
}
而且,在插件项目中,我创建扩展这种方式:
project.getExtensions().create("myplugin", MyPluginExtension.class);
但在我的客户项目,当我应用程式LY和配置如上所示的插件,我得到这个错误:
Gradle DSL method not found: 'property2()'
我如何定义我MyPluginExtension
类property2
关闭?
编辑
我已经试过这样:
public class MyPluginExtension { //root extension
String property1;
Property2 peroperty2;
//getters and setters
public void property2(Closure c) {
c.setResolveStrategy(Closure.DELEGATE_FIRST);
c.setDelegate(property2);
c.call();
}
}
但现在我得到这个错误:
Gradle DSL method not found: a1()
它无法解决嵌套封场。
谢谢。如果我使用Java而不是Groovy,那么呢? –
只需使用java语法定义它。也应该工作。 – Opal
谢谢。我试过了,似乎解决了,但现在它不能解决嵌套闭包字段。看看我的编辑。 –