Compile gradle project with another project as a dependency


imagesHaving project dependant on another project is common situation. How to configure gradle so that it will include your dependency project in build process?

There are two cases:

1. Your project is a root project and dependency is under its root(从属关系

When dependand project is under root in a directory structure (dependency is not being shared with any other project except this one) you are doing it in recommended gradle strategy :)

To wrap up: you have directory structure like this:

Project
  |--build.gradle
  |--settings.gradle
  |--Dependency
  |    |--build.gradle

Then to add Dependency to Project, you need to have Project/settings.gradle content like this:

include ':Dependency'

and in a Project/build.gradle dependencies section you need to compile the dependent project by adding:

dependencies {
   compile project(':Dependency')
}

2. You have two independent projects and you need to use one of them as a dependency(平级关系

When both project are on the same level in a directory structure you are not doing it as gradle team wish, but it is more real world situation in my opinion :) This is because you have your library project that can be easily used in several other projects as a dependency.

So you have directory structure like this:

Project
  |--build.gradle
  |--settings.gradle
Dependency
  |--build.gradle

To add Dependency to the Project, you need to include it, and show Dependency path manually. So the Project/settings.gradle content should be like this:

include ':Dependency'
project(':Dependency').projectDir = new File(settingsDir, '../Dependency')

and in a Project/build.gradle dependencies section you need to compile the dependent project by adding:

dependencies {
   compile project(':Dependency')
}

Notice that tis is build.gradle is exactly the same as in previous section.

Did I help you?
I manage this blog and share my knowledge for free, sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

来自:https://looksok.wordpress.com/2014/07/12/compile-gradle-project-with-another-project-as-a-dependency/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

VCHH

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值