如何解释Gradle DSL [英] How to interpret Gradle DSL
问题描述
任务hello {
doLast {
println'Hello world!'
}
}
我知道这个脚本是在 Project
。所以我可以从 Project
documentation 中有一些重载的任务(...)
方法。看着签名,我需要选择一个具有闭包作为最终参数的签名。由于我们在这里没有传入 Map
,我假设被调用的方法是 task(String name,Closure closure)
$ b
然而,我正在努力的部分是在这个脚本中,字符串 hello
被映射到字符串
。
另一个例子是 example 6.7 :
任务taskX(dependsOn:'taskY')<< {
println'taskX'
}
任务taskY<< {
println'taskY'
}
在这里,我假设我们调用该方法的任务(Map< String,?> args,String name)
窗体。但是,
- 同样,字符串
taskX
最终是作为String
? - 鉴于圆括号不用于构造
Map
括号中的部分最终如何成为Map
? - 如果我正确地计算出哪个方法被调用,aren是否在脚本中以错误的顺序给出的参数与DSL文档相比较?
- 使用括号的语法查找所有世界,如方法调用。这可能表示委派给
项目
对象来解析taskX
作为未知方法。但是,由于方法调用紧接在它之前的task
,AFAIK方法调用在这一点上在语法上不是有效的。
正如您所看到的,我对于示例语法如何映射到DSL参考指南感到有点困惑,这对于我真正理解发生的事情有点棘手在基层一级。
谢谢!
task foo
任务声明语法的变体特别之处在于它使用Groovy编译器插件实现。据我所知,这是使用编译器插件来支持特殊语法的唯一情况。
I'm trying to learn Gradle. My preferred style of learning is to understand at a low level what is going on. To that end, I am trying to interpret what's happening in example 6.1 of the documentation with respect to the DSL reference:
task hello {
doLast {
println 'Hello world!'
}
}
I understand that this script is executed in the context of a Project
. So I can see from the Project
documentation that there are a number of overloaded task(...)
methods. Looking at the signatures, I need to chose one which has a closure as the final argument. And since we're not passing a Map
here, I assume the method that's being called is task(String name, Closure closure)
.
However, the part I'm struggling with is how, in this script, the literal string hello
gets mapped to a String
.
Another example is example 6.7:
task taskX(dependsOn: 'taskY') << {
println 'taskX'
}
task taskY << {
println 'taskY'
}
Here, I assume we're calling the task(Map<String, ?> args, String name)
form of the method. But,
- Again, how does the literal string
taskX
end up as aString
? - Given that parentheses are not used to construct a
Map
literal, how does the part in parentheses end up being aMap
? - If I've correctly figured out which method is being called, aren't the arguments given in the wrong order in the script compared to the DSL documentation?
- The syntax using parentheses looks for all the world like a method call. Which might indicate delegation to the
Project
object to resolvetaskX
as an unknown method. But, AFAIK, a method call wouldn't be syntactically valid at this point given the method call totask
immediately preceding it.
As you can see I'm a bit confused as to how the example syntax maps down to the DSL reference guide, which is making it a bit tricky for me to really understand what's happening at a grass-roots level.
Thanks!
The task foo
variation of the task declaration syntax is special in that it's implemented using a Groovy compiler plugin. As far as I know, this is the only case where a compiler plugin is used to support a special syntax.
这篇关于如何解释Gradle DSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!