AutoCloseable, Closeablepublic interface ProjectConnection extends Closeable
Represents a long-lived connection to a Gradle project. You obtain an instance of a ProjectConnection by using GradleConnector.connect().
try (ProjectConnection connection = GradleConnector.newConnector()
.forProjectDirectory(new File("someFolder"))
.connect()) {
//obtain some information from the build
BuildEnvironment environment = connection.model(BuildEnvironment.class).get();
//run some tasks
connection.newBuild()
.forTasks("tasks")
.setStandardOutput(System.out)
.run();
}
All implementations of ProjectConnection are thread-safe, and may be shared by any number of threads.
All notifications from a given ProjectConnection instance are delivered by a single thread at a time. Note, however, that the delivery thread may change over time.
| Modifier and Type | Method | Description |
|---|---|---|
BuildActionExecuter.Builder |
action() |
Creates a builder for an executer which can be used to run actions in different phases of the build.
|
<T> BuildActionExecuter<T> |
action(BuildAction<T> buildAction) |
Creates an executer which can be used to run the given action when the build has finished.
|
void |
close() |
Closes this connection.
|
<T> T |
getModel(Class<T> modelType) |
Fetches a snapshot of the model of the given type for this project.
|
<T> void |
getModel(Class<T> modelType,
ResultHandler<? super T> handler) |
Starts fetching a snapshot of the given model, passing the result to the given handler when complete.
|
<T> ModelBuilder<T> |
model(Class<T> modelType) |
Creates a builder which can be used to query the model of the given type.
|
BuildLauncher |
newBuild() |
Creates a launcher which can be used to execute a build.
|
TestLauncher |
newTestLauncher() |
Creates a test launcher which can be used to execute tests.
|
<T> T getModel(Class<T> modelType) throws GradleConnectionException, IllegalStateException
This method is simply a convenience for calling model(modelType).get()
T - The model type.modelType - The model type.UnsupportedVersionException - When the target Gradle version does not support the given model.UnknownModelException - When the target Gradle version or build does not support the requested model.BuildException - On some failure executing the Gradle build, in order to build the model.GradleConnectionException - On some other failure using the connection.IllegalStateException - When this connection has been closed or is closing.<T> void getModel(Class<T> modelType, ResultHandler<? super T> handler) throws IllegalStateException
ResultHandler.onComplete(Object) method.
If the operation fails, the handler's ResultHandler.onFailure(GradleConnectionException) method is called with the appropriate exception.
See getModel(Class) for a description of the various exceptions that the operation may fail with.
This method is simply a convenience for calling model(modelType).get(handler)
T - The model type.modelType - The model type.handler - The handler to pass the result to.IllegalStateException - When this connection has been closed or is closing.BuildLauncher newBuild()
Requires Gradle 1.0-milestone-8 or later.
TestLauncher newTestLauncher()
Requires Gradle 2.6 or later.
<T> ModelBuilder<T> model(Class<T> modelType)
Any of following models types may be available, depending on the version of Gradle being used by the target build:
GradleBuildBuildEnvironmentGradleProjectBuildInvocationsProjectPublicationsIdeaProjectBasicIdeaProjectEclipseProjectHierarchicalEclipseProjectA build may also expose additional custom tooling models. You can use this method to query these models.
Requires Gradle 1.0-milestone-8 or later.
T - The model type.modelType - The model type<T> BuildActionExecuter<T> action(BuildAction<T> buildAction)
Requires Gradle 1.8 or later.
T - The result type.buildAction - The action to run.if you want to hook into different points of the build lifecycle.@Incubating BuildActionExecuter.Builder action()
Requires Gradle 4.8 or later.
void close()
close in interface AutoCloseableclose in interface Closeable