简体   繁体   English

Gradle中依赖项的依赖项

[英]Dependencies of dependencies in Gradle

I am studying Gradle and I am trying to find best practices with it. 我正在学习Gradle,正在尝试寻找最佳实践。

The project that I will describe is built successful. 我将描述的项目已成功构建。 You can clone on GitHub, it is a eclipse/java project: https://github.com/pauloleitemoreira/GradleTests.git 您可以在GitHub上进行克隆,这是一个eclipse / java项目: https : //github.com/pauloleitemoreira/GradleTests.git

Assume that I have a MainProject with some file modules dependencies that not belong to the MainProject. 假设我有一个MainProject,其中某些文件模块依赖项不属于MainProject。

Project Structure 项目结构

x-MainProject
|        |
|        x-mainModule 
|
x-LibProject
|        |
|        x-libModule
|
x-BaseLibProject
         |
         x-baseLibModule

MainProject/setting.gradle file: MainProject / setting.gradle文件:

include ':mainModule'

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

/*???*/include ':BaseLibProject', ':BaseLibProject:baseLibModule'
/*???*/project(':BaseLibProject').projectDir = new File(settingsDir, '../BaseLibProject')
/*???*/project(':BaseLibProject:baseLibModule').projectDir = new File(settingsDir, '../BaseLibProject/baseLibModule')

LibProject/setting.gradle file: LibProject / setting.gradle文件:

include ':libModule'

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

BaseLibProject/setting.gradle file: BaseLibProject / setting.gradle文件:

include 'baseLibModule'

I noticed that only the MainProject/setting.gradle file is executed when Build. 我注意到在Build时仅执行MainProject / setting.gradle文件。 The others LibProject/setting.gradle and BaseLibProject/setting.gradle are not executed when I am building the MainProject. 当我构建MainProject时,不会执行其他LibProject / setting.gradle和BaseLibProject / setting.gradle。

I marked with /*???*/ the lines that sound weird for me, because I suppose that libModule would have to know where are your dependencies. 我用/*???*/标记了听起来很奇怪的行,因为我想libModule必须知道您的依赖项在哪里。 In my understanding, these lines isn't necessary and gradle could include BaseLibModule when LibModule is built. 以我的理解,这些行不是必需的,并且在构建LibModule时,gradle可以包括BaseLibModule。 But unfortunately, if I take out these lines, the project won't build. 但是不幸的是,如果我删除这些行,该项目将无法构建。

I was thinking if there is another place to put project(':...').projectDir = new File... , in a way to avoid to include Dependency of dependency files? 我在想是否还有其他地方可以放置project(':...').projectDir = new File... ,以避免包含依赖性文件的依赖性?

Build lifecycle chapter in Gradle user guide explains how multi-project builds work. Gradle用户指南中的构建生命周期一章介绍了多项目构建的工作方式。 Simple version is that there is one settings.gradle in root project folder that defines what projects are included in build. 简单的版本是在根项目文件夹中有一个settings.gradle ,它定义了构建中包括哪些项目。 Each project can have build.gradle (or the name can be different or the file may be missing). 每个项目都可以具有build.gradle (或名称可以不同或文件可能丢失)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM