摇篮

API文档:Gradle

代表 Gradle 的调用。

您可以Gradle通过调用 来获取实例Project.getGradle()

特性

财产描述
extensions

扩展的容器。

gradle

返回此Gradle实例。此方法在初始化脚本中非常有用,可以显式访问 Gradle 属性和方法。例如,使用gradle.parent比使用更能表达你的意图 parent。此属性还允许您从可能隐藏属性的范围(例如从方法或闭包)访问 Gradle 属性。

gradleHomeDir

Gradle 主目录(如果有)。该目录是包含执行此构建的 Gradle 发行版的目录。

gradleUserHomeDir

Gradle 用户主目录。该目录用于缓存下载的资源、编译好的构建脚本等。

gradleVersion

当前的 Gradle 版本。

includedBuilds

此版本包含的版本。

parent

此构建的父构建(如果有)。

pluginManager

此插件感知对象的插件管理器。

plugins

已应用于此对象的插件的容器。

rootProject

此构建的根项目。

startParameter

用于StartParameter启动此构建。

taskGraph

对于TaskExecutionGraph这个构建。

方法

方法描述
addBuildListener(buildListener)

将 a 添加BuildListener到此 Build 实例。侦听器会收到构建执行期间发生的事件的通知。

addListener(listener)

将给定的监听器添加到此构建中。监听器可以实现任何给定的监听器接口:

addProjectEvaluationListener(listener)

向此构建添加一个侦听器,以在评估项目时接收通知。

afterProject(closure)

添加一个在项目评估后立即调用的闭包。该项目作为第一个参数传递给闭包。项目评估失败(如果有)作为第二个参数传递。这两个参数都是可选的。

afterProject(action)

添加在评估项目后立即调用的操作。

allprojects(action)

添加针对此构建的所有项目执行的操作。该操作会立即针对所有可用的项目执行。当后续项目添加到此构建时也会执行它。

apply(closure)

应用零个或多个插件或脚本。

apply(options)

使用作为地图提供的给定选项来应用插件或脚本。如果插件已被应用,则不执行任何操作。

apply(action)

应用零个或多个插件或脚本。

beforeProject(closure)

添加在评估项目之前立即调用的闭包。该项目作为参数传递给闭包。

beforeProject(action)

添加要在评估项目之前立即调用的操作。

beforeSettings(closure)

添加在加载和评估构建设置之前要调用的操作。

beforeSettings(action)

添加在加载和评估构建设置之前要调用的操作。

buildFinished(closure)
已弃用

Adds a closure to be called when the build is completed. All selected tasks have been executed. A BuildResult instance is passed to the closure as a parameter.

buildFinished(action)
Deprecated

Adds an action to be called when the build is completed. All selected tasks have been executed.

includedBuild(name)

Returns the included build with the specified name for this build.

projectsEvaluated(closure)

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. This Gradle instance is passed to the closure as a parameter.

projectsEvaluated(action)

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.

projectsLoaded(closure)

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. This Gradle instance is passed to the closure as a parameter.

projectsLoaded(action)

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.

removeListener(listener)

Removes the given listener from this build.

removeProjectEvaluationListener(listener)

Removes the given listener from this build.

rootProject(action)

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.

settingsEvaluated(closure)

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. The Settings object is passed to the closure as a parameter.

settingsEvaluated(action)

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.

useLogger(logger)

Uses the given object as a logger. The logger object may implement any of the listener interfaces supported by Gradle.addListener(java.lang.Object).

Script blocks

No script blocks

Property details

ExtensionContainer extensions (read-only)

The container of extensions.

Gradle gradle (read-only)

Returns this 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.

File gradleHomeDir (read-only)

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 Manual.

File gradleUserHomeDir (read-only)

The Gradle user home directory. This directory is used to cache downloaded resources, compiled build scripts and so on.

String gradleVersion (read-only)

The current Gradle version.

Collection<IncludedBuild> includedBuilds (read-only)

The included builds for this build.

Gradle parent (read-only)

The parent build of this build, if any.

PluginManager pluginManager (read-only)

The plugin manager for this plugin aware object.

PluginContainer plugins (read-only)

The container of plugins that have been applied to this object.

While not deprecated, it is preferred to use the methods of this interface or the PluginAware.getPluginManager() than use the plugin container.

Use one of the 'apply' methods on this interface or on the PluginAware.getPluginManager() to apply plugins instead of applying via the plugin container.

Use PluginManager.hasPlugin(java.lang.String) or similar to query for the application of plugins instead of doing so via the plugin container.

Project rootProject (read-only)

The root project of this build.

StartParameter startParameter (read-only)

The StartParameter used to start this build.

TaskExecutionGraph taskGraph (read-only)

The TaskExecutionGraph for this build.

Method details

void addBuildListener(BuildListener buildListener)

Adds a BuildListener to this Build instance. The listener is notified of events which occur during the execution of the build.

void addListener(Object listener)

Adds the given listener to this build. The listener may implement any of the given listener interfaces:

The following listener types can be used, but are not supported when configuration caching is enabled. Their usage is deprecated and adding a listener of these types become an error in a future Gradle version:

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. 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.

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. The action is executed immediately against all projects which are already available. It is also executed as subsequent projects are added to this build.

void apply(Closure closure)

Applies zero or more plugins or scripts.

The given closure is used to configure an ObjectConfigurationAction, which “builds” the plugin application.

This method differs from PluginAware.apply(java.util.Map) in that it allows methods of the configuration action to be invoked more than once.

void apply(Map<String, ?> options)

Applies a plugin or script, using the given options provided as a map. Does nothing if the plugin has already been applied.

The given map is applied as a series of method calls to a newly created ObjectConfigurationAction. That is, each key in the map is expected to be the name of a method ObjectConfigurationAction and the value to be compatible arguments to that method.

The following options are available:

  • from: A script to apply. Accepts any path supported by Project.uri(java.lang.Object).
  • plugin: The id or implementation class of the plugin to apply.
  • to: The target delegate object or objects. The default is this plugin aware object. Use this to configure objects other than this object.

void apply(Action<? super ObjectConfigurationAction> action)

Applies zero or more plugins or scripts.

The given closure is used to configure an ObjectConfigurationAction, which “builds” the plugin application.

This method differs from PluginAware.apply(java.util.Map) in that it allows methods of the configuration action to be invoked more than once.

void beforeProject(Closure closure)

Adds a closure to be called immediately before a project is evaluated. The project is passed to the closure as a parameter.

void beforeProject(Action<? super Project> action)

Adds an action to be called immediately before a project is evaluated.

void beforeSettings(Closure<?> closure)

Adds an action to be called before the build settings have been loaded and evaluated.

void beforeSettings(Action<? super Settings> action)

Adds an action to be called before the build settings have been loaded and evaluated.

void buildFinished(Closure closure)

Note: This method is deprecated and will be removed in the next major version of Gradle.

Adds a closure to be called when the build is completed. All selected tasks have been executed. A BuildResult instance is passed to the closure as a parameter.

void buildFinished(Action<? super BuildResult> action)

Note: This method is deprecated and will be removed in the next major version of Gradle.

Adds an action to be called when the build is completed. All selected tasks have been executed.

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. The project objects are fully configured and are ready to use to populate the task graph. This Gradle instance is passed to the closure as a parameter.

void projectsEvaluated(Action<? super Gradle> action)

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.

void projectsLoaded(Closure closure)

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. This 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 {
      //...
    }
  }
}

void projectsLoaded(Action<? super Gradle> action)

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.

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. If the root project is already available, the action is executed immediately. Otherwise, the action is executed when the root project becomes available.

void settingsEvaluated(Closure closure)

添加一个在加载和评估构建设置时调用的闭包。设置对象已完全配置并准备好用于加载构建项目。该 Settings对象作为参数传递给闭包。

void settingsEvaluated(行动)Action<? super Settings>

添加在加载和评估构建设置时要调用的操作。设置对象已完全配置并准备好用于加载构建项目。

void useLoggerObject记录器)

使用给定对象作为记录器。记录器对象可以实现 所支持的任何侦听器接口 Gradle.addListener(java.lang.Object)

每个监听器接口都有一个关联的记录器。当您使用给定侦听器类型的记录器调用此方法时,新记录器将替换当前与侦听器类型关联的任何记录器。这允许您针对某些类型的事件有选择地用您自己的实现替换 Gradle 提供的标准日志记录。