如何解读 Gradle DSL [英] How to interpret Gradle DSL
问题描述
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屋!