How does ivypublication syntax works?

(Baiyan Huang) #1

For example:

publishing {
  publications {
    myPublication(IvyPublication) {
      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?


(Peter Niederwieser) #2

Not sure if I understand the question, but ‘myPublication’ is the name of the publication, and ‘IvyPublication’ the type.

(Baiyan Huang) #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:


(Peter Niederwieser) #4

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.

(Baiyan Huang) #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:, 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?

(Peter Niederwieser) #6

‘myPublication’ is the (dynamic) method name that gets trapped because no physical method with that name exists The trap then calls ‘create’.