api / org.gradle.tooling / GradleConnector / <init>

<init>

GradleConnector()

A GradleConnector is the main entry point to the Gradle tooling API. You use this API as follows:

  1. Call #newConnector() to create a new connector instance.
  2. Configure the connector. You must call #forProjectDirectory(java.io.File) to specify which project you wish to connect to. Other methods are optional.
  3. Call #connect() to create the connection to a project.
  4. When finished with the connection, call ProjectConnection#close() to clean up.

Example:

 ProjectConnection connection = GradleConnector.newConnector() .forProjectDirectory(new File("someProjectFolder")) .connect(); try { connection.newBuild().forTasks("tasks").run(); } finally { connection.close(); } 

The connection will use the version of Gradle that the target build is configured to use, for example in the Gradle wrapper properties file. When no Gradle version is defined for the build, the connection will use the tooling API's version as the Gradle version to run the build. Generally, you should avoid configuring a Gradle distribution or version and instead use the default provided by the tooling API.

Similarly, the connection will use the JVM and JVM arguments that the target build is configured to use, for example in the gradle.properties file. When no JVM or JVM arguments are defined for the build, the connection will use the current JVM and some default JVM arguments.

GradleConnector instances are not thread-safe. If you want to use a GradleConnector concurrently you must always create a new instance for each thread using #newConnector(). Note, however, the ProjectConnection instances that a connector creates are completely thread-safe.

Gradle version compatibility

The Tooling API is both forwards and backwards compatible with other versions of Gradle. It supports execution of Gradle builds that use older or newer versions of Gradle.

The current version of the Tooling API supports running builds using Gradle versions 1.2.

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 for builds using 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 2.0 or later.

Java version compatibility

The Tooling API requires Java 8 or later. Java 7 is currently still supported but will be removed in Gradle 5.0. The Gradle version used by builds may have additional Java version requirements.

Since
1.0-milestone-3