A GradleConnector
is the main entry point to the Gradle tooling API. You use this API as follows:
ProjectConnection connection = GradleConnector.newConnector() .forProjectDirectory(new File("someProjectFolder")) .connect(); try { connection.newBuild().forTasks("tasks").run(); } finally { connection.close(); }
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.
Type | Name and description |
---|---|
ProjectConnection |
connect() Creates a connection to the project in the specified project directory. |
GradleConnector |
forProjectDirectory(File projectDir) Specifies the working directory to use. |
static CancellationTokenSource |
newCancellationTokenSource() Creates a new CancellationTokenSource that can be used to cancel one or more LongRunningOperation executions. |
static GradleConnector |
newConnector() Creates a new connector instance. |
GradleConnector |
useDistribution(URI gradleDistribution) Specifies which Gradle distribution to use. |
GradleConnector |
useGradleUserHomeDir(File gradleUserHomeDir) Specifies the user's Gradle home directory to use. |
GradleConnector |
useGradleVersion(String gradleVersion) Specifies which Gradle version to use. |
GradleConnector |
useInstallation(File gradleHome) Specifies which Gradle installation to use. |
Creates a connection to the project in the specified project directory. You should call ProjectConnection.close when you are finished with the connection.
Specifies the working directory to use.
projectDir
- The working directory.Creates a new CancellationTokenSource that can be used to cancel one or more LongRunningOperation executions.
null
.Creates a new connector instance.
Specifies which Gradle distribution to use. The appropriate distribution is downloaded and installed into the user's Gradle home directory. This replaces any value specified using useInstallation(java.io.File) or useGradleVersion(String). Defaults to a project-specific Gradle version.
gradleDistribution
- The distribution to use. Specifies the user's Gradle home directory to use. Defaults to ~/.gradle
.
gradleUserHomeDir
- The user's Gradle home directory to use.Specifies which Gradle version to use. The appropriate distribution is downloaded and installed into the user's Gradle home directory. This replaces any value specified using useInstallation(java.io.File) or useDistribution(java.net.URI). Defaults to a project-specific Gradle version.
gradleVersion
- The version to use.Specifies which Gradle installation to use. This replaces any value specified using useDistribution(java.net.URI) or useGradleVersion(String). Defaults to a project-specific Gradle version.
gradleHome
- The Gradle installation directory.