Ueli Hofstetter
Ueli Hofstetter

Reputation: 2524

Gradle configuration/dependency syntax

I am struggling to understand the gradle groovy syntax for dependencies and what is going on behind the scenes. As a starter I don't see what is exactly happening in this code snippet ....

dependencies {
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
}

What I (hope to) understand (please correct if I am wrong):

What I don't understand:

Upvotes: 0

Views: 428

Answers (1)

Johan Stuyts
Johan Stuyts

Reputation: 3687

Gradle (like other tools built with Groovy) makes lots of use of methodMissing(...): http://www.groovy-lang.org/metaprogramming.html#_methodmissing

So what happens in the case of dependencies is that you invoke a method that does not exist. The method name is the name of the configuration, and its arguments are the dependency specification.

methodMissing(...) will be called and this will in turn call one of the add(...) methods of DependencyHandler: https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/dsl/DependencyHandler.html

Upvotes: 3

Related Questions