public abstract class GradleConnector extends Object
A GradleConnector
is the main entry point to the Gradle tooling API. You use this API as follows:
newConnector()
to create a new connector instance.forProjectDirectory(java.io.File)
to specify which project you wish to connect to. Other methods are optional.connect()
to create the connection to a project.ProjectConnection.close()
to clean up.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.
Constructor and Description |
---|
GradleConnector() |
Modifier and Type | Method and Description |
---|---|
abstract ProjectConnection |
connect()
Creates a connection to the project in the specified project directory.
|
abstract GradleConnector |
forProjectDirectory(File projectDir)
Specifies the working directory to use.
|
static GradleConnector |
newConnector()
Creates a new connector instance.
|
abstract GradleConnector |
useDistribution(URI gradleDistribution)
Specifies which Gradle distribution to use.
|
abstract GradleConnector |
useGradleUserHomeDir(File gradleUserHomeDir)
Specifies the user's Gradle home directory to use.
|
abstract GradleConnector |
useGradleVersion(String gradleVersion)
Specifies which Gradle version to use.
|
abstract GradleConnector |
useInstallation(File gradleHome)
Specifies which Gradle installation to use.
|
public static GradleConnector newConnector()
public abstract GradleConnector useInstallation(File gradleHome)
useDistribution(java.net.URI)
or useGradleVersion(String)
. Defaults to a project-specific
Gradle version.gradleHome
- The Gradle installation directory.public abstract GradleConnector useGradleVersion(String gradleVersion)
useInstallation(java.io.File)
or useDistribution(java.net.URI)
. Defaults to a project-specific Gradle version.gradleVersion
- The version to use.public abstract GradleConnector useDistribution(URI gradleDistribution)
useInstallation(java.io.File)
or useGradleVersion(String)
. Defaults to a project-specific Gradle version.gradleDistribution
- The distribution to use.public abstract GradleConnector forProjectDirectory(File projectDir)
projectDir
- The working directory.public abstract GradleConnector useGradleUserHomeDir(File gradleUserHomeDir)
~/.gradle
.gradleUserHomeDir
- The user's Gradle home directory to use.public abstract ProjectConnection connect() throws GradleConnectionException, UnsupportedVersionException
ProjectConnection.close()
when you are finished with the connection.UnsupportedVersionException
- When the target Gradle version does not support this version of the tooling API.GradleConnectionException
- On failure to establish a connection with the target Gradle version.