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

摘要:
build.gradle里的dependencies标签页:如果把dependencies改成dependencies2,gradlebuild的输出会遇到错误消息:Aproblemoccurredevaluatingrootproject'quickstart'.Couldnotfindmethoddependencies2()forarguments[build_a2307i03s3k13jd

build.gradle里的dependencies标签页:

build.gradle里dependencies标签页的实现原理第1张

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

build.gradle里dependencies标签页的实现原理第2张

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类,位于目录orggradleapi下面:

build.gradle里dependencies标签页的实现原理第3张

打开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标签页的实现原理第4张

里面定义了dependencies这个方法:

build.gradle里dependencies标签页的实现原理第5张

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

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

build.gradle里dependencies标签页的实现原理第6张

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标签页的实现原理第7张

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标签页的实现原理第8张

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

build.gradle里dependencies标签页的实现原理第9张

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://repo.maven.apache.org/maven2/commons-collections-/commons-collections/3.2.2/commons-collections-3.2.2.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project :

从错误信息的url能看出gradle build下载依赖的地址:https://repo.maven.apache.org/maven2/commons-collections-/commons-collections/3.2.2/commons-collections-3.2.2.pom

如果把url里多余的-去掉,在浏览器里即可正常访问:

https://repo.maven.apache.org/maven2/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.pom

build.gradle里dependencies标签页的实现原理第10张

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
build.gradle里dependencies标签页的实现原理第11张

免责声明:文章转载自《build.gradle里dependencies标签页的实现原理》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇高中生该如何申请美国大学?不妨看一下NCBI SRA数据如何进行md5校验?下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

Practical Shader Development: Vertex and Fragment Shaders for Game Developers (Kyle Hallady 著)

这是我们描述形状的方法之一,它将使计算机变得有意义。要定义形状,我们需要存储关于三件事的信息:顶点、边和面。顶点是三维空间中的点。边是连接顶点的最内层。面是由三个或多个角度形成的二维形状。你不能把脸想象成只有在记忆中恢复的一个网格的垂直面之间的空间,而每一个共享的需要和脸都是由垂直面顺序简单定义的。因为很多名字都不会出现在网格的“背面”,所以正面的哪一面很重...

uniapp打包h5 出现'连接服务器超时,点击屏幕重试'的页面

跟踪以首先找出原因全局组件AsyncErrorNew在中注册。js文件可以自定义。我很快就过去了,所以我添加了一个空白页面,然后在清单中介绍了组件。json文件...

以『公众号』为例,手把手教你爬取PC端数据

“appmsgext_url=origin_url+”__biz={}&mid={}&sn={}&idx={}&appmsg_token={}&x5=1“.formatcontent=requests.post.json()打印打印可以看到帖子已成功发送,并提取相应的阅读号、点赞号和观看号。5。同一个公众号被扩展。如果...

C#使用FFMPEG推流,并且获取流保存在本地,随时取媒体进行播放!

最近,基于C#的拖缆的发展并不理想。最后,经过不懈的努力,我取得了一些成绩。这是一张便条;本文重点介绍如何将ffmpeg用于简单的流式传输。如果没有官方文档WithFilter.WithField,简单的代码行似乎很难。拉动();以上是流和获取流的核心代码,保存在本地=TargetType。Live){thrownewApplicationException...

Chrome 浏览器快捷键

谷歌Chrome可以记住最近关闭的10个标签。Shift+Alt+T将焦点设置在浏览器工具栏中的第一个工具上。按空格键或Enter键激活工具栏按钮,包括网页操作和浏览器操作。Ctrl+Shift+Delete将打开“清除浏览数据”对话框。同时按下Ctrl键和左箭头键。主页转到页面顶部。Ctrl+X或Shift+Delete将删除高亮显示的内容并将其复制到剪贴...