lzprgmr
(Baiyan Huang)
December 25, 2013, 9:24am
1
For example:
publishing {
publications {
myPublication(IvyPublication) {
from components.java
artifact(sourceJar) {
type "source"
extension "src.jar"
conf "runtime"
}
descriptor.withXml {
asNode().info[0].appendNode("description", "custom-description")
}
}
}
}
Here the publication is declared as: myPublication(IvyPublication), which is of format: var_name(type) {}, what kind of syntax is this?
Thanks.
Not sure if I understand the question, but ‘myPublication’ is the name of the publication, and ‘IvyPublication’ the type.
lzprgmr
(Baiyan Huang)
December 26, 2013, 1:30am
3
Yea, I know what it means, but I just don’t understand the syntax, could we actually define a variable in groovy/gradle this way:
variable_name(type)
num(int)
Technically, ‘myPublication(IvyPublication) { …}’ is a dynamic method call with two arguments that Gradle traps and interprets as the name, type, and configuration block of a publication, respectively.
lzprgmr
(Baiyan Huang)
December 26, 2013, 3:58am
5
Thanks Peter, but I am afraid I am still not following: myPublication is the name parameter, IvyPublication is the type parameters, {…} is the configuration part, then where is the function?
I found on this page: http://www.gradle.org/docs/current/dsl/org.gradle.api.publish.PublicationContainer.html , there is actually such a function:
publishing.publications.create('publication-name', IvyPublication) {
// Configure the ivy publication here
}
is that calling the create function underlying, but how does this syntax maps to a function call?
‘myPublication’ is the (dynamic) method name that gets trapped because no physical method with that name exists The trap then calls ‘create’.