[英]How to apply plugin as Map in Gradle's build script?
How can I apply plugin as Map in Gradle? 如何在Gradle中将插件应用为Map? We can use:
我们可以用:
Map<String, String> map = new HashMap<String, String>()
map.put('plugin', 'java')
apply(map)
But when write: 但是当写:
apply [plugin:'java']
An error occured. 发生错误。 Why?
为什么?
The correct Groovy syntax to pass a map to a method is apply the: "map"
or apply([the: "map"])
. 要将映射传递给方法的正确Groovy语法,请
apply the: "map"
或apply([the: "map"])
。 apply[...]
is subscript syntax (such as when indexing into an array) which isn't defined here. apply[...]
是下标语法(例如,在索引到数组时),此处未定义。
apply([plugin:'java'])
or apply plugin:'java'
will work but not apply[plugin:'java']
. apply([plugin:'java'])
或apply plugin:'java'
将起作用,但apply[plugin:'java']
无效。
apply
, most likely, is groovy method call and someMethod[key:value]
is not valid groovy method call. apply
很可能是常规的方法调用,而someMethod[key:value]
是无效的常规方法调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.