Table of Contents
Gradle provides a programmatic API called the Tooling API, which you can use for embedding Gradle into your own software. 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; however, the API is open for anyone who needs to embed Gradle in their application.
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, including versions that are both newer and older than the version of the Tooling API that you are using. The Tooling API is Gradle wrapper aware and, by default, uses the same target Gradle version as that used by the wrapper-powered project.
Some features that the Tooling API provides:
The Tooling API always uses the Gradle daemon. This means that subsequent calls to the Tooling API, be it model building requests or task executing requests will be executed in the same long-living process. Chapter 6, The Gradle Daemon contains more details about the daemon, specifically information on situations when new daemons are forked.
As the Tooling API is an interface for developers, the Javadoc is the main documentation for it. We provide several samples that live
in samples/toolingApi
in your Gradle distribution. These samples specify all of the required dependencies for the Tooling API with examples for
querying information from Gradle builds and executing tasks from the Tooling API.
The main entry point to the Tooling API is the GradleConnector
. You can navigate from there to find code samples and
explore the available Tooling API models.
There are two ways of using the GradleConnector
to connect to a Gradle build.
GradleConnector.connect()
to create a ProjectConnection
.
A ProjectConnection
connects to a single Gradle project. Using the connection you can execute tasks, tests and retrieve models relative to this project.
This is the original API provided by the Tooling API. Use this API when you wish to use a stable non-incubating API.
GradleConnector.newGradleConnection()
to create a
GradleConnectionBuilder
.
GradleConnectionBuilder
can be used to connect to any number of Gradle builds at one time. Executing tasks and retrieving models are performed in the context
of the composite. Instead of retrieving a single model for a single Gradle project, the Tooling API can provide all models for all projects with a single method call.
Note that this API is currently incubating and may change at any time.
The current version of the Tooling API supports running builds using Gradle versions 1.0-milestone-8 and later. Support for versions from 1.0-milestone-8 to 1.1 is deprecated and will be removed from the Tooling API in Gradle 3.0.
You should note that not all features of the Tooling API are available for all versions of Gradle. For example, build cancellation is only available when a build uses Gradle 2.1 and later. Refer to the documentation for each class and method for more details.
The current Gradle version can be used from Tooling API versions 1.2 or later. Support for execution using tooling API versions 1.2 to 1.12 is deprecated and will be removed in Gradle 3.0.
The Tooling API requires Java 6 or later. Support for Java 6 is currently deprecated and will be removed in Gradle 3.0.