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里多余的-去掉,在浏览器里即可正常访问:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关推荐
kafka切换阿里云镜像配置文件build.gradle, 解决com.github.spotbugs报错问题。
当我们创建一个Android项目时会包含两个Android build.gradle配置详解文件,如下图: 一、Project的build.gradle文件: 对应的build.gradle代码如下: // Top-level build file where you can add configuration...
Gradle 配置阿里云,配置国内代理,配置HTTPS,替换maven central,替换google,替换gradle plugin,替换jcenter,全部项目可使用,放入%GRADLE_HOME%\init.d文件夹中即可
又称:查看我的build.gradle! 调用build.gradles。 非常欢迎您使用自己项目的build.gradle文件提出请求。 常问问题 有趣的项目。 为什么创建它? 我开始一个新项目,然后想通了,我问我的Android开发伙伴,他们...
主要给大家介绍了关于Android中build.gradle文件的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
.gradle\caches\modules-2\files-2.1\com.android.tools.build\gradle缓存文件,包含pom,jar,source
参考本项目的build.gradle,修改项目里的build.gradle(注意是项目不是库),增加以下两个dependencies: classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' classpath '...
hive-jdbc精简依赖jar包 gradle配置,原本项目打包之后只有30多兆,接入hive-jdbc之后,发现包直接跳到了快90兆,后来想办法逐步把jar包精简出来,亲测可用
Gradle配置Gretty插件所需的两个文件(build.gradle、gretty.plugin)