Why can I set a task property without using =?

Today I realized that I used the following in my build:

war {

archiveName ‘ROOT.war’

}

and that it worked fine, although the War task documentation doesn’t list any method named ‘archiveName’. The task has a property named ‘archiveName’, and I’m thus surprised I don’t have to use the following syntax to set the archive name:

war {

archiveName = ‘ROOT.war’

}

So, to help me in my quest to better understand groovy and gradle, could someone tell me

  • if setting a property without using ‘=’ is a groovy thing, or if it’s a gradle thing

  • if this is documented somewhere (I searched hard, but didn’t find anything)

  • if it’s a good practice or not

  • if this syntax is usable for any property of any object, or if it’s limited to some types of objects/properties

  • how and where it is implemented (if it’s a gradle thing)

Thank you.

Gradle does class decoration to support things like extensions, extra properties and convention mapping.

One of the other things it does is add what we call “setter methods” for writable properties. That is, where there is a ‘setFoo(String)’ method, we generate a ‘foo(String)’ method and delegate to it. The one exception to this is if the property extends ‘Collection’, then we don’t generate the methods.

This is currently undocumented.

Thanks Luke.

I’ll refrain from using this syntax then. I have the feeling that it brings more confusion than help, at least for me.