How does ivypublication syntax works?

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?


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

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:


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.

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?

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