资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

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

本篇内容主要讲解“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标签页的实现原理是什么”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


新闻名称:build.gradle里dependencies标签页的实现原理是什么
当前URL:http://cdkjz.cn/article/ggsgsj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220