Interface Gradle
- All Superinterfaces:
PluginAware
You can obtain a Gradle
instance by calling Project.getGradle()
.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addBuildListener
(BuildListener buildListener) Adds aBuildListener
to this Build instance.void
addListener
(Object listener) Adds the given listener to this build.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.Returns thisGradle
instance.Returns the Gradle home directory, if any.Returns the Gradle user home directory.Returns the current Gradle version.Returns the included builds for this build.Returns the parent build of this build, if any.Returns the root project of this build.Returns theStartParameter
used to start this build.Returns theTaskExecutionGraph
for this build.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
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
Uses the given object as a logger.Methods inherited from interface org.gradle.api.plugins.PluginAware
apply, apply, apply, getPluginManager, getPlugins
-
Method Details
-
getGradleVersion
String getGradleVersion()Returns the current Gradle version.- Returns:
- The Gradle version. Never returns null.
-
getGradleUserHomeDir
File getGradleUserHomeDir()Returns the Gradle user home directory. This directory is used to cache downloaded resources, compiled build scripts and so on.- Returns:
- The user home directory. Never returns null.
-
getGradleHomeDir
Returns the Gradle home directory, if any. This directory is the directory containing the Gradle distribution executing this build.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 guide.
- Returns:
- The home directory. May return null.
-
getParent
Returns the parent build of this build, if any.- Returns:
- The parent build. May return null.
-
getRootProject
Returns the root project of this build.- Returns:
- The root project. Never returns null.
- Throws:
IllegalStateException
- When called before the root project is available.
-
rootProject
Adds an action to execute against the root project of this build. If the root project is already available, the action is executed immediately. Otherwise, the action is executed when the root project becomes available.- Parameters:
action
- The action to execute.
-
allprojects
Adds an action to execute against all projects of this build. The action is executed immediately against all projects which are already available. It is also executed as subsequent projects are added to this build.- Parameters:
action
- The action to execute.
-
getTaskGraph
TaskExecutionGraph getTaskGraph()Returns theTaskExecutionGraph
for this build.- Returns:
- The task graph. Never returns null.
-
getStartParameter
StartParameter getStartParameter()Returns theStartParameter
used to start this build.- Returns:
- The start parameter. Never returns null.
-
addProjectEvaluationListener
Adds a listener to this build, to receive notifications as projects are evaluated.- Parameters:
listener
- The listener to add. Does nothing if this listener has already been added.- Returns:
- The added listener.
-
removeProjectEvaluationListener
Removes the given listener from this build.- Parameters:
listener
- The listener to remove. Does nothing if this listener has not been added.
-
beforeProject
Adds a closure to be called immediately before a project is evaluated. The project is passed to the closure as a parameter.- Parameters:
closure
- The closure to execute.
-
beforeProject
Adds an action to be called immediately before a project is evaluated.- Parameters:
action
- The action to execute.- Since:
- 3.4
-
afterProject
Adds a closure to be called immediately after a project is evaluated. The project is passed to the closure as the first parameter. The project evaluation failure, if any, is passed as the second parameter. Both parameters are optional.- Parameters:
closure
- The closure to execute.
-
afterProject
Adds an action to be called immediately after a project is evaluated.- Parameters:
action
- The action to execute.- Since:
- 3.4
-
buildStarted
Adds a closure to be called when the build is started. ThisGradle
instance is passed to the closure as the first parameter.- Parameters:
closure
- The closure to execute.
-
buildStarted
Adds an action to be called when the build is started.- Parameters:
action
- The action to execute.- Since:
- 3.4
-
settingsEvaluated
Adds a closure to be called when the build settings have been loaded and evaluated. The settings object is fully configured and is ready to use to load the build projects. TheSettings
object is passed to the closure as a parameter.- Parameters:
closure
- The closure to execute.
-
settingsEvaluated
Adds an action to be called when the build settings have been loaded and evaluated. The settings object is fully configured and is ready to use to load the build projects.- Parameters:
action
- The action to execute.- Since:
- 3.4
-
projectsLoaded
Adds a closure to be called when the projects for the build have been created from the settings. None of the projects have been evaluated. ThisGradle
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 { //... } } }
- Parameters:
closure
- The closure to execute.
-
projectsLoaded
Adds an action to be called when the projects for the build have been created from the settings. None of the projects have been evaluated.- Parameters:
action
- The action to execute.- Since:
- 3.4
-
projectsEvaluated
Adds a closure to be called when all projects for the build have been evaluated. The project objects are fully configured and are ready to use to populate the task graph. ThisGradle
instance is passed to the closure as a parameter.- Parameters:
closure
- The closure to execute.
-
projectsEvaluated
Adds an action to be called when all projects for the build have been evaluated. The project objects are fully configured and are ready to use to populate the task graph.- Parameters:
action
- The action to execute.- Since:
- 3.4
-
buildFinished
Adds a closure to be called when the build is completed. All selected tasks have been executed. ABuildResult
instance is passed to the closure as a parameter.- Parameters:
closure
- The closure to execute.
-
buildFinished
Adds an action to be called when the build is completed. All selected tasks have been executed.- Parameters:
action
- The action to execute.- Since:
- 3.4
-
addBuildListener
Adds aBuildListener
to this Build instance. The listener is notified of events which occur during the execution of the build.- Parameters:
buildListener
- The listener to add.
-
addListener
Adds the given listener to this build. The listener may implement any of the given listener interfaces:- Parameters:
listener
- The listener to add. Does nothing if this listener has already been added.
-
removeListener
Removes the given listener from this build.- Parameters:
listener
- The listener to remove. Does nothing if this listener has not been added.
-
useLogger
Uses the given object as a logger. The logger object may implement any of the listener interfaces supported byaddListener(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.
- Parameters:
logger
- The logger to use.
-
getGradle
Gradle getGradle()Returns thisGradle
instance. This method is useful in init scripts to explicitly access Gradle properties and methods. For example, usinggradle.parent
can express your intent better than usingparent
. 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.- Returns:
- this. Never returns null.
-
getIncludedBuilds
Returns the included builds for this build.- Since:
- 3.1
-
includedBuild
Returns the included build with the specified name for this build.- Since:
- 3.1
-