设为首页 加入收藏

TOP

Chapter 8. Introduction to multi-project builds 多工程构建介绍(一)
2017-10-13 10:04:58 】 浏览:3459
Tags:Chapter Introduction multi-project builds 工程 构建 介绍

Only the smallest of projects has a single build file and source tree, unless it happens to be a massive, monolithic application. It’s often much easier to digest and understand a project that has been split into smaller, inter-dependent modules. The word “inter-dependent” is important, though, and is why you typically want to link the modules together through a single build.

Gradle supports this scenario through multi-project builds.

8.1. Structure of a multi-project build

Such builds come in all shapes and sizes, but they do have some common characteristics:

//gradle具有的一些通用的特性

  • settings.gradle file in the root or master directory of the project  //在项目的根目录下有一个settings.gradle文件

  • build.gradle file in the root or master directory   //在根目录下有一个build.gradle文件

  • Child directories that have their own *.gradle build files (some multi-project builds may omit child project build scripts)  //每个子目录有他们自己的*.gradle文件

The settings.gradle file tells Gradle how the project and subprojects are structured. Fortunately, you don’t have to read this file simply to learn what the project structure is as you can run the command gradle projects. Here's the output from using that command on the Java multiproject build in the Gradle samples:

//settings.gradle文件告诉gradle工程和子工程是如何被组织的。幸运的是,你不需要读这个文件来了解项目结构,你可以使用gradle projects命令。例子如下:

Example 8.1. Listing the projects in a build

Output of gradle -q projects

> gradle -q projects

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'multiproject'
+--- Project ':api'
+--- Project ':services'
|    +--- Project ':services:shared'
|    \--- Project ':services:webservice'
\--- Project ':shared'

To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :api:tasks

 

This tells you that multiproject has three immediate child projects: apiservices and shared. The services project then has its own children, shared and webservice. These map to the directory structure, so it’s easy to find them. For example, you can find webservice in <root>/services/webservice.

Each project will usually have its own build file, but that's not necessarily the case. In the above example, the services project is just a container or grouping of other subprojects. There is no build file in the corresponding directory. However, multiproject does have one for the root project.

//每一个项目通常会有一个自己的build文件,但是这不是必须要有的。在上面的例子中,services工程就是一个其他子工程的容器,因此在其对应的目录下没有build文件。然后多工程必须在根目录下有一个build文件

The root build.gradle is often used to share common configuration between the child projects, for example by applying the same sets of plugins and dependencies to all the child projects. It can also be used to configure individual subprojects when it is preferable to have all the configuration in one place. This means you should always check the root build file when discovering how a particular subproject is being configured.

//根目录下的build.gradle文件通常被用来共享子工程的通用配置,例如给所有的子工程应用相同的插件设置。它也可以用来配置子工程的独立配置,这意味着当研究某一个特定子工程是

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Chapter 7. Dependency Managemen.. 下一篇Creating Lists and Cards 创建列..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目