我是 Gradle 新手,我正在阅读文档,但我不明白其中的某些部分。这些部分之一与 buildscript
block 连接。它的目的是什么?
If your build script needs to use external libraries, you can add them to the script's classpath in the build script itself. You do this using the buildscript() method, passing in a closure which declares the build script classpath.
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
block 确定哪些插件、任务类和其他类可在构建脚本的其余部分中使用。如果没有 buildScript
block ,您可以使用 Gradle 开箱即用的所有内容。如果您还想使用第三方插件、任务类或其他类(在构建脚本中!),则必须在 buildScript
block 中指定相应的依赖项。
关于classpath - Gradle 中 buildscript block 的用途,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17773817/