问题描述
我是 Gradle 的新手,我正在阅读文档,但我不明白其中的某些部分.这些部分之一与 buildscript
块相连.它的目的是什么?
I am new to Gradle and I am reading the documentation but I don't understand some parts of it. One of these parts is connected with buildscript
block. What is its purpose?
如果您的构建脚本需要使用外部库,您可以将它们添加到构建脚本本身的脚本类路径中.您可以使用 buildscript() 方法执行此操作,传入一个声明构建脚本类路径的闭包.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'commons-codec', name: 'commons-codec', version: '1.2'
}
}
好的,但有什么区别:
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-codec', name: 'commons-codec', version: '1.2'
}
比如为什么要使用buildscript
?
推荐答案
buildScript
块确定哪些插件、任务类和其他类可用于构建的其余部分脚本.如果没有 buildScript
块,您可以开箱即用地使用 Gradle 附带的所有内容.如果您还想使用第三方插件、任务类或其他类(在构建脚本中!),您必须在 buildScript
块中指定相应的依赖项.
The buildScript
block determines which plugins, task classes, and other classes are available for use in the rest of the build script. Without a buildScript
block, you can use everything that ships with Gradle out-of-the-box. If you additionally want to use third-party plugins, task classes, or other classes (in the build script!), you have to specify the corresponding dependencies in the buildScript
block.
这篇关于Gradle 中 buildscript 块的用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!