日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/19 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 build.gradle里dependencies标签页的实现原理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

build.gradle里的dependencies標簽頁:

如果把dependencies改成dependencies2, gradle build的輸出會遇到錯誤消息:

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下面:

打開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是一個接口:

里面定義了dependencies這個方法:

這個方法的實現在哪里呢?

將dependencies標簽頁里的implementation標簽隨便換個名字:

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出錯:

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類的成員:

再把dependenies里的group屬性值稍作修改,改成一個并不存在的庫文件名:

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

要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":

總結

以上是生活随笔為你收集整理的build.gradle里dependencies标签页的实现原理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。