gradle依赖项如何工作 [英] How gradle dependencies work

查看:90
本文介绍了gradle依赖项如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我浏览gradle dsl指南时,我注意到DependencyHandler。执行依赖性方法时,将其委托给闭包。就像

依赖项{
compile'c​​ommons-lang:commons-lang:2.6'
}

我不明白的是为什么 compile'c​​ommons-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆