从Gradle扩展中访问配置闭包 [英] Accessing the configure closure from a gradle extension
问题描述
project.extensions.create('myExtension')这是一个插件, ,新的MyExtension(项目))
其中 MyExtension
是定义我的新功能的类。
现在,在 gradle.build
中可以这样做:
myExtension {
//配置很酷的东西
}
现在我想要做的是在配置闭包中消费一些东西,然后传递闭包的其余部分,对于我定义的任务,使用 project.configure(myTask,closure)
。然而,我不知道如何从 MyExtension $ c>访问配置闭包
-
-
消费一些闭包,即访问闭包的一些属性,然后剥离它们,留下另一个闭包所有未触及的东西,但没有其他的东西
任何指针将不胜感激=)
这不是扩展的工作方式。立即评估闭包以配置扩展对象。之后,封闭消失了。通常情况下,插件将使用扩展对象中包含的信息来进一步配置任务。
PS:它是 extensions.create('myExtension ',MyExtension,project)
,而不是 project.extensions.create('myExtension',new MyExtension(project))
。
I'm writing a plugin in which do something like the following:
project.extensions.create('myExtension', new MyExtension(project))
where MyExtension
is the class that defines my new functionality.
Now, in gradle.build
I can do this:
myExtension {
// configure cool stuff
}
What I would like to do now, is to "consume" a couple of the things in this configure closure, and pass the rest of the closure as-is to a task I defined, using project.configure(myTask, closure)
. However, I have no idea how to
Access the configure closure from the
MyExtension
class."Consume" some of the closure, i.e. access some of the properties on the closure and then strip them, leaving another closure which has all the untouched things but nothing else
Any pointers would be greatly appreciated =)
It's not how extensions work. The closure gets evaluated immediately in order to configure the extension object. After that, the closure is gone. Typically, a plugin will use the (information contained in the) extension object to further configure tasks.
PS: It's extensions.create('myExtension', MyExtension, project)
, not project.extensions.create('myExtension', new MyExtension(project))
.
这篇关于从Gradle扩展中访问配置闭包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!