版权声明:本文为大事龙原创文章,未经允许不得转载。 https://blog.csdn.net/w_yunlong/article/details/78995771
问题背景
在使用多模块开发时,通常一个模块(A)可能会需要其它模块(B)中的类或方法,这时就产生了依赖关系,也就是 A 依赖 B。
要解决上述依赖,有两种方案
- 1、将B发布到 repo 仓库(可以为本地仓库)
- 2、A直接依赖B
1、将 B 发布到仓库,修改 B 模块中的 build.gradle,增加
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: uri("../../repo"))
}
}
}
其中B模块具有如下配置:
group 'com.test'
version '0.0.1'
这时在模块A中,就可以在 build.gradle 文件的 dependencies 节点,增加:
compile 'com.test:b:0.0.1'
2、A 直接依赖模块 B
在 A 模块中的 build.gradle 的 dependencies 节点,增加:
compile project(':b')