你的位置:首页 > 软件开发 > 操作系统 > Chapter 8. Introduction to multi

Chapter 8. Introduction to multi

发布时间:2016-06-12 15:00:06
Only the smallest of projects has a single build file and source tree, unless it happens to be a massive, monolithic application. It&rsq ...

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

 

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文件通常被用来共享子工程的通用配置,例如给所有的子工程应用相同的插件设置。它也可以用来配置子工程的独立配置,这意味着当研究某一个特定子工程是如何被配置的问题时,根目录的build.gradle文件应该是需要查看的。

Another thing to bear in mind is that the build files might not be called build.gradle. Many projects will name the build files after the subproject names, such asapi.gradle and services.gradle from the previous example. Such an approach helps a lot in IDEs because it’s tough to work out which build.gradle file out of twenty possibilities is the one you want to open. This little piece of magic is handled by the settings.gradle file, but as a build user you don’t need to know the details of how it’s done. Just have a look through the child project directories to find the files with the .gradle suffix.

//另一个事需要了解的是,build文件可能不叫build.gradle.很多工程会自己命名子工程下的build文件,例如上面例子中的api.gradle 和 services.gradle.这种方法帮了IDE很大的忙,因为让ide从20多重可能的文件中找到你想要打开的那个build文件是艰难的。这个处理逻辑在setting.gradle文件中。

Once you know what subprojects are available, the key question for a build user is how to execute the tasks within the project.

原标题:Chapter 8. Introduction to multi

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录