Gradle中buildscript块的用途 [英] Purpose of buildscript block in Gradle

查看:380
本文介绍了Gradle中buildscript块的用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Gradle新手,正在阅读文档,但我不明白它的某些部分。其中一个部分与 buildscript 块连接。它的目的是什么?


如果您的构建脚本需要使用外部库,您可以将它们添加到脚本的构建脚本本身的类路径。您可以使用buildscript()方法执行此操作,并传入一个声明构建脚本classpath的闭包。 $ b

  buildscript {
repositories {
mavenCentral()
}
依赖项{
classpath组:'commons-codec',名称:'commons-codec',版本:'1.2'
}
}


确定,但与以下内容有什么不同:


$ b

  repositories {
mavenCentral()
}
依赖关系{
编译组:'commons-codec',名称:'commons-codec',版本:'1.2'
}

例如,为什么需要使用 buildscript

解决方案

buildScript 块决定哪些插件,任务类和其他类可用于构建脚本的其余部分。如果没有 buildScript 块,您可以使用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?

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'
  }
}

Ok but what is the difference with:

repositories {
  mavenCentral()
}
dependencies {
  compile group: 'commons-codec', name: 'commons-codec', version: '1.2'
}

For example, why it is necessary to use 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块的用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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