当前位置:   article > 正文

gradle一个项目引用另一个项目的解决方法_gradle引用其他模块

gradle引用其他模块

Compile gradle project with another project as a dependency

Having 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.

 

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/778687
推荐阅读
相关标签
  

闽ICP备14008679号