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

    打开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的原创文章,请关注公众号"汪子熙":

  • 相关阅读:
    UPS FAQ-不错的UPS资料
    HPL.dat FAQ
    Fortran77计算某段代码的CPU运行时间
    存储知识 什么是LUN?LUN有什么用?对理解存储设备很有好处
    HPL.dat Tune
    UPS-瓦特(W)和伏安(VA):易混淆的两个概念
    mysql sql 索引相关用法,加快查询速度
    mysql 数据库分类设计方法与PHP结合
    c# SQLServer 数据库连接类
    .net上传图片生成大小缩略图
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/13287261.html
Copyright © 2020-2023  润新知