1.0 里程碑 3 发行版带来了新 API,叫 tooling API,可用于嵌入 Gradle。这个 API 允许你执行和监视构建,以及向 Gradle 查询有关构建的细节。它的主要受众是 IDE,CI 服务器,其他的 UI 作者或你的 Gradle 插件的集成测试。不过,它是向所有需要在其应用程序中嵌入 Gradle 的人开放的。
The 1.0 milestone 3 release brought a new API called the tooling API, which you can use for embedding Gradle. This API allows you to execute and monitor builds, and to query Gradle about the details of a build. The main audience for this API is IDE, CI server, other UI authors, or integration testing of your Gradle plugins. However, it is open for anyone who needs to embed Gradle in their application.
这个 tooling API 的基本特征是它以独立于版本的方式运行。这意味着你可以使用同一 API 来处理不同目标g版本的 Gradle。Toolin API 是能感知到 Gradle 包装器的,默认情况下,它使用与包装器驱动的项目相同的 Gradle 版本。
A fundamental characteristic of the tooling API is that it operates in a version independent way. This means that you can use the same API to work with different target versions of Gradle. The tooling API is Gradle wrapper aware and, by default, uses the same target Gradle version as that used by the wrapper-powered project.
目前这个 tooling API 提供了以下这些功能:
Some features that the tooling API provides today:
将来我们可能会支持一些其他有趣的功能:
In future we may support other interesting features:
请查看《第 19 章,Gradle 守护进程》。Tooling API 全程使用守护进程,举例来说,没有守护进程,你就不能正式使用 Tooling API。这意味着后续调用 Tooling API 时,都会在同一个长期存活的进程中执行构建请求或任务执行请求的模型。《第 19 章,Gradle 守护进程》包含了有关守护进程的更多详细内容,特别是有关派生新守护程序情况的内容。
Please take a look at Chapter 19, The Gradle Daemon. The Tooling API uses the daemon all the time, e.g. you cannot officially use the Tooling API without the daemon. This means that subsequent calls to the Tooling API, be it model building requests or task executing requests can be executed in the same long-living process. Chapter 19, The Gradle Daemon contains more details about the daemon, specifically information on situations when new daemons are forked.
由于Tooling API 是面向程序员的接口,因此大部分的文档都在 Javadoc 中。这正是我们的目的——我们不希望本章节内容篇幅太大。相反,我们将添加更多的代码示例并改进 Javadoc 文档。Tooling API 的主要入口点是 GradleConnector
。你可以从该处浏览并找到代码示例及其他说明。学习如何使用Tooling API 的有效方法是检出并运行 $gradleHome/samples/toolingApi
中的 示例。
Since the tooling API is an interface for a programmer most of the documentation lives in the Javadoc. This is exactly our intention - we don't expect this chapter to grow very much. Instead we will add more code samples and improve the Javadoc documentation. The main entry point to the tooling API is the GradleConnector
. You can navigate from there and find code samples and other instructions. Pretty effective way of learning how to use the tooling API is checking out and running the samples that live in $gradleHome/samples/toolingApi
.
如果你正在嵌入 Gradle,并且正在寻找 tooling API 所需要的确切依赖,那么请查看 $gradleHome/samples/toolingApi
中的样本。依赖是在 Gradle 构建脚本中声明的。你还可以找到获取 Jar 的仓库声明。
If you're embedding Gradle and you're looking for exact set of dependencies the tooling API Jar requires please look at one of the samples in $gradleHome/samples/toolingApi
. The dependencies are declared in the Gradle build scripts. You can also find the repository declarations where the Jars are obtained from.