温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

build.gradle里dependencies标签页的实现原理是什么

发布时间:2021-11-01 10:25:23 来源:亿速云 阅读:349 作者:iii 栏目:编程语言

本篇内容主要讲解“build.gradle里dependencies标签页的实现原理是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“build.gradle里dependencies标签页的实现原理是什么”吧!

build.gradle里的dependencies标签页:

build.gradle里dependencies标签页的实现原理是什么

如果把dependencies改成dependencies2, gradle build的输出会遇到错误消息:

build.gradle里dependencies标签页的实现原理是什么

A problem occurred evaluating root project 'quickstart'.

Could not find method dependencies2() for arguments [build_a2307i03s3k13jdug3afl2lin$_run_closure3@21c69f73] on root project 'quickstart' of type org.gradle.api.Project.

找到这个org.gradle.api.Project类,位于目录org\gradle\api下面:

build.gradle里dependencies标签页的实现原理是什么

打开Project.java, 查看关于dependencies的说明:

A project generally has a number of dependencies it needs in order to do its work. Also, a project generally * produces a number of artifacts, which other projects can use. Those dependencies are grouped in configurations, and * can be retrieved and uploaded from repositories. You use the {@link org.gradle.api.artifacts.ConfigurationContainer} * returned by {@link #getConfigurations()} method to manage the configurations. The {@link * org.gradle.api.artifacts.dsl.DependencyHandler} returned by {@link #getDependencies()} method to manage the * dependencies. The {@link org.gradle.api.artifacts.dsl.ArtifactHandler} returned by {@link #getArtifacts()} method to * manage the artifacts. The {@link org.gradle.api.artifacts.dsl.RepositoryHandler} returned by {@link * #getRepositories()} method to manage the repositories.

Project是一个接口:

build.gradle里dependencies标签页的实现原理是什么

里面定义了dependencies这个方法:

build.gradle里dependencies标签页的实现原理是什么

这个方法的实现在哪里呢?

将dependencies标签页里的implementation标签随便换个名字:

build.gradle里dependencies标签页的实现原理是什么

gradle build出错:

A problem occurred evaluating root project 'quickstart'. Could not find method implementation2() for arguments [{group=commons-collections, name=commons-collections, version=3.2.2}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

说明Implementation标签页的实现就位于org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler类里.

group改成group2:

build.gradle里dependencies标签页的实现原理是什么

build出错:

A problem occurred evaluating root project 'quickstart'. Could not set unknown property 'group2' for DefaultExternalModuleDependency{group='null', name='commons-collections', version='3.2.2', configuration='default'} of type org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency.

所以build.gradle文件dependencies里的标签对应了DefaultExternalModuleDependency类的实例. 前者dependencies属性group, name和version对应了DefaultExternalModuleDependency类的成员:

build.gradle里dependencies标签页的实现原理是什么

再把dependenies里的group属性值稍作修改,改成一个并不存在的库文件名:

build.gradle里dependencies标签页的实现原理是什么

gradle build报错:

Could not resolve all files for configuration ':compileClasspath'. Could not find commons-collections-:commons-collections:3.2.2. Searched in the following locations: - https://aven2/commons-collections-/commons-collections/3.2.2/commons-collections-3.2.2.pomhttps://aven2/commons-collections-/commons-collections/3.2.2/commons-collections-3.2.2.pomhttps://aven2/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.pom


build.gradle里dependencies标签页的实现原理是什么


到此,相信大家对“build.gradle里dependencies标签页的实现原理是什么”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI