How gradle dependencies work

2019-07-11 21:33发布

问题:

When I walk through the gradle dsl guide, I notice the DependencyHandler. It's delegated to closure when execute dependencies method. Just like dependencies { compile 'commons-lang:commons-lang:2.6' } The point I can't understand is why "compile 'commons-lang:commons-lang:2.6'" caused the method "add(configurationName, dependencyNotation)" be invoked.

回答1:

Internally Gradle uses Groovy's metaprogramming features, specifically methodMissing, to implement this capability. You can see how this is done in the DependencyHandler implementation.