gradle依赖项如何工作 [英] How gradle dependencies work
问题描述
当我浏览gradle dsl指南时,我注意到DependencyHandler。执行依赖性方法时,将其委托给闭包。就像
依赖项{
compile'commons-lang:commons-lang:2.6'
}
我不明白的是为什么 compile'commons-lang:commons-lang:2.6'会导致方法 add(configurationName,dependencyNotation)被调用。
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.
推荐答案
Gradle内部使用Groovy的元编程功能,特别是 methodMissing 来实现此功能。您可以在 DependencyHandler
实现。
Internally Gradle uses Groovy's metaprogramming features, specifically methodMissing, to implement this capability. You can see how this is done in the DependencyHandler
implementation.
这篇关于gradle依赖项如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!