PluginAware
public interface Gradle extends PluginAware
You can obtain a Gradle
instance by calling Project.getGradle()
.
Modifier and Type | Method | Description |
---|---|---|
void |
addBuildListener(BuildListener buildListener) |
Adds a
BuildListener to this Build instance. |
void |
addListener(Object listener) |
Adds the given listener to this build.
|
ProjectEvaluationListener |
addProjectEvaluationListener(ProjectEvaluationListener listener) |
Adds a listener to this build, to receive notifications as projects are evaluated.
|
void |
afterProject(Closure closure) |
Adds a closure to be called immediately after a project is evaluated.
|
void |
afterProject(Action<? super Project> action) |
Adds an action to be called immediately after a project is evaluated.
|
void |
allprojects(Action<? super Project> action) |
Adds an action to execute against all projects of this build.
|
void |
beforeProject(Closure closure) |
Adds a closure to be called immediately before a project is evaluated.
|
void |
beforeProject(Action<? super Project> action) |
Adds an action to be called immediately before a project is evaluated.
|
void |
buildFinished(Closure closure) |
Adds a closure to be called when the build is completed.
|
void |
buildFinished(Action<? super BuildResult> action) |
Adds an action to be called when the build is completed.
|
void |
buildStarted(Closure closure) |
Adds a closure to be called when the build is started.
|
void |
buildStarted(Action<? super Gradle> action) |
Adds an action to be called when the build is started.
|
Gradle |
getGradle() |
Returns this
Gradle instance. |
File |
getGradleHomeDir() |
Returns the Gradle home directory, if any.
|
File |
getGradleUserHomeDir() |
Returns the Gradle user home directory.
|
String |
getGradleVersion() |
Returns the current Gradle version.
|
Collection<IncludedBuild> |
getIncludedBuilds() |
Returns the included builds for this build.
|
Gradle |
getParent() |
Returns the parent build of this build, if any.
|
Project |
getRootProject() |
Returns the root project of this build.
|
StartParameter |
getStartParameter() |
Returns the
StartParameter used to start this build. |
TaskExecutionGraph |
getTaskGraph() |
Returns the
TaskExecutionGraph for this build. |
IncludedBuild |
includedBuild(String name) |
Returns the included build with the specified name for this build.
|
void |
projectsEvaluated(Closure closure) |
Adds a closure to be called when all projects for the build have been evaluated.
|
void |
projectsEvaluated(Action<? super Gradle> action) |
Adds an action to be called when all projects for the build have been evaluated.
|
void |
projectsLoaded(Closure closure) |
Adds a closure to be called when the projects for the build have been created from the settings.
|
void |
projectsLoaded(Action<? super Gradle> action) |
Adds an action to be called when the projects for the build have been created from the settings.
|
void |
removeListener(Object listener) |
Removes the given listener from this build.
|
void |
removeProjectEvaluationListener(ProjectEvaluationListener listener) |
Removes the given listener from this build.
|
void |
rootProject(Action<? super Project> action) |
Adds an action to execute against the root project of this build.
|
void |
settingsEvaluated(Closure closure) |
Adds a closure to be called when the build settings have been loaded and evaluated.
|
void |
settingsEvaluated(Action<? super Settings> action) |
Adds an action to be called when the build settings have been loaded and evaluated.
|
void |
useLogger(Object logger) |
Uses the given object as a logger.
|
apply, apply, apply, getPluginManager, getPlugins
String getGradleVersion()
File getGradleUserHomeDir()
@Nullable File getGradleHomeDir()
When using the “Gradle Daemon”, this may not be the same Gradle distribution that the build was started with. If an existing daemon process is running that is deemed compatible (e.g. has the desired JVM characteristics) then this daemon may be used instead of starting a new process and it may have been started from a different “gradle home”. However, it is guaranteed to be the same version of Gradle. For more information on the Gradle Daemon, please consult the User Manual.
@Nullable Gradle getParent()
Project getRootProject() throws IllegalStateException
IllegalStateException
- When called before the root project is available.void rootProject(Action<? super Project> action)
action
- The action to execute.void allprojects(Action<? super Project> action)
action
- The action to execute.TaskExecutionGraph getTaskGraph()
TaskExecutionGraph
for this build.StartParameter getStartParameter()
StartParameter
used to start this build.ProjectEvaluationListener addProjectEvaluationListener(ProjectEvaluationListener listener)
listener
- The listener to add. Does nothing if this listener has already been added.void removeProjectEvaluationListener(ProjectEvaluationListener listener)
listener
- The listener to remove. Does nothing if this listener has not been added.void beforeProject(Closure closure)
closure
- The closure to execute.void beforeProject(Action<? super Project> action)
action
- The action to execute.void afterProject(Closure closure)
closure
- The closure to execute.void afterProject(Action<? super Project> action)
action
- The action to execute.void buildStarted(Closure closure)
Gradle
instance is passed to the closure as the first parameter.closure
- The closure to execute.void buildStarted(Action<? super Gradle> action)
action
- The action to execute.void settingsEvaluated(Closure closure)
Settings
object is passed to the closure as a parameter.closure
- The closure to execute.void settingsEvaluated(Action<? super Settings> action)
action
- The action to execute.void projectsLoaded(Closure closure)
Gradle
instance is passed to the closure as a parameter.
An example of hooking into the projectsLoaded to configure buildscript classpath from the init script.
//init.gradle gradle.projectsLoaded { rootProject.buildscript { repositories { //... } dependencies { //... } } }
closure
- The closure to execute.void projectsLoaded(Action<? super Gradle> action)
action
- The action to execute.void projectsEvaluated(Closure closure)
Gradle
instance is passed to the closure as a parameter.closure
- The closure to execute.void projectsEvaluated(Action<? super Gradle> action)
action
- The action to execute.void buildFinished(Closure closure)
BuildResult
instance is passed to the closure as a parameter.closure
- The closure to execute.void buildFinished(Action<? super BuildResult> action)
action
- The action to execute.void addBuildListener(BuildListener buildListener)
BuildListener
to this Build instance.
The listener is notified of events which occur during the execution of the build.buildListener
- The listener to add.void addListener(Object listener)
listener
- The listener to add. Does nothing if this listener has already been added.void removeListener(Object listener)
listener
- The listener to remove. Does nothing if this listener has not been added.void useLogger(Object logger)
addListener(Object)
.
Each listener interface has exactly one associated logger. When you call this method with a logger of a given listener type, the new logger will replace whichever logger is currently associated with the listener type. This allows you to selectively replace the standard logging which Gradle provides with your own implementation, for certain types of events.
logger
- The logger to use.Gradle getGradle()
Gradle
instance.
This method is useful in init scripts to explicitly access Gradle
properties and methods. For example, using gradle.parent
can express your intent better than using
parent
. This property also allows you to access Gradle properties from a scope where the property
may be hidden, such as, for example, from a method or closure.Collection<IncludedBuild> getIncludedBuilds()
IncludedBuild includedBuild(String name) throws UnknownDomainObjectException
UnknownDomainObjectException
- when there is no build with the given name