How does Gradle make use of the artifactHandler.add method by default?


#1

On the artifactHandler docs http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.dsl.ArtifactHandler.html, the following code is defined:

artifacts {
  //configuration name and the task:
  schema schemaJar
}

It appears the following is also equivalent:

artifacts {
   add('schema', schemaJar)
}

What property of Gradle/Groovy makes these calls equivalent? Reading the docs, how is one supposed to know that add() is called implicitly?


(Peter Niederwieser) #2

What property of Gradle/Groovy makes these calls equivalent?

The implementation of ‘ArtifactHandler’, which uses a Groovy ‘methodMissing’ hook.

Reading the docs, how is one supposed to know that add() is called implicitly?

As a build script author, you shouldn’t have to know, but it shouldn’t be too hard to figure this out from the docs. It’s a common idiom in the Gradle APIs.