build.gradle 中的 buildscript 和 allprojects 有什么区别? [英] What's the difference between buildscript and allprojects in build.gradle?

查看:13
本文介绍了build.gradle 中的 buildscript 和 allprojects 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多项目 gradle 构建中,有人能告诉我allprojects"部分和buildscript"部分之间到底有什么区别吗?两者都有一个 repositoriesdependencies 任务.我的项目是 allprojects 吗?buildscript 呢?

On a multi-project gradle build, can someone tell me what exactly is the difference between the "allprojects" section and the "buildscript" one? Both have a repositories and dependencies task. Is allprojects for my project? What about buildscript?

buildscript {  
     repositories {
         ...
     }
     dependencies {
         ...
     }
}

allprojects(subprojects) { 
     repositories {
         ...
     }
     dependencies {
         ...
     }
}

推荐答案

buildscript"配置部分用于 gradle 本身(即更改 gradle 执行构建的方式).所以这部分通常会包含 Android Gradle 插件.

The "buildscript" configuration section is for gradle itself (i.e. changes to how gradle is able to perform the build). So this section will usually include the Android Gradle plugin.

allprojects"部分用于 Gradle 构建的模块.

The "allprojects" section is for the modules being built by Gradle.

通常两者的存储库部分是相同的,因为两者通常都会从 jcenter(或者可能是 maven Central)获取它们的依赖项.但是依赖项"部分会有所不同.

Oftentimes the repository section is the same for both, since both will get their dependencies from jcenter usually (or maybe maven central). But the "dependencies" section will be different.

通常,allprojects"的依赖项"部分是空的,因为每个模块的依赖项都是唯一的,并且将位于每个模块内的build.gradle"文件中.但是,如果所有模块都共享相同的依赖项,那么它们可以在此处列出.

Usually the "dependencies" section for "allprojects" is empty since the dependencies for each module are unique and will be in the "build.gradle" file within each of the modules. However, if all of the modules shared the same dependencies then they could be listed here.

这篇关于build.gradle 中的 buildscript 和 allprojects 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆