interface ExtensionAware
Objects that can be extended at runtime with other objects.
// Extensions are just plain objects, there is no interface/type class MyExtension { String foo MyExtension(String foo) { this.foo = foo } } // Add new extensions via the extension container project.extensions.create('custom', MyExtension, "bar") // («name», «type», «constructor args», …) // extensions appear as properties on the target object by the given name assert project.custom instanceof MyExtension assert project.custom.foo == "bar" // also via a namespace method project.custom { assert foo == "bar" foo = "other" } assert project.custom.foo == "other" // Extensions added with the extension container's create method are themselves extensible assert project.custom instanceof ExtensionAware project.custom.extensions.create("nested", MyExtension, "baz") assert project.custom.nested.foo == "baz" // All extension aware objects have a special “ext” extension of type ExtraPropertiesExtension assert project.hasProperty("myProperty") == false project.ext.myProperty = "myValue" // Properties added to the “ext” extension are promoted to the owning object assert project.myProperty == "myValue"
Many Gradle objects are extension aware. This includes; projects, tasks, configurations, dependencies etc.
For more on adding & creating extensions, see ExtensionContainer.
For more on extra properties, see ExtraPropertiesExtension.
An ExtensionAware
object has several 'scopes' that Gradle searches for properties. These scopes are:
propertyMissing()
. Care must be taken by plugin authors to ensure propertyMissing()
is implemented such that if a property is not found a MissingPropertyException(String, Class) exception is thrown. If propertyMissing()
always returns a value for any property, Gradle will not search the rest of the scopes below.
abstract fun getExtensions(): ExtensionContainer
The container of extensions. |
val ExtensionAware.extra: ExtraPropertiesExtension
The extra properties extension in this object's extension container. |
fun <T : Any> ExtensionAware.configure(configuration: T.() -> Unit): Unit
Executes the given configuration block against the extension of the specified type. |
|
fun <T : Any> ExtensionAware.the(): T
Returns the extension of the specified type. fun <T : Any> ExtensionAware.the(extensionType: KClass<T>): T
Returns the extension of the specified extensionType. |
interface Project : Comparable<Project>, ExtensionAware, PluginAware
This interface is the main API you use to interact with Gradle from your build file. From a There is a one-to-one relationship between a
A project is essentially a collection of Task objects. Each task performs some basic piece of work, such as compiling classes, or running unit tests, or zipping up a WAR file. You add tasks to a project using one of the A project generally has a number of dependencies it needs in order to do its work. Also, a project generally produces a number of artifacts, which other projects can use. Those dependencies are grouped in configurations, and can be retrieved and uploaded from repositories. You use the org.gradle.api.artifacts.ConfigurationContainer returned by Projects are arranged into a hierarchy of projects. A project has a name, and a fully qualified path which uniquely identifies it in the hierarchy. Plugins Plugins can be used to modularise and reuse project configuration. Plugins can be applied using the Gradle executes the project's build file against the For example:
You can also access the A project has 5 property 'scopes', which it searches for properties. You can access these properties by name in your build file, or by calling the project's
When reading a property, the project searches the above scopes in order, and returns the value from the first scope it finds the property in. If not found, an exception is thrown. See When writing a property, the project searches the above scopes in order, and sets the property in the first scope it finds the property in. If not found, an exception is thrown. See Reading extra properties is done through the "ext" or through the owning object. Dynamic Methods
A project has 5 method 'scopes', which it searches for methods:
|
|
interface Task : Comparable<Task>, ExtensionAware
A Each task belongs to a Project. You can use the various methods on to create and lookup task instances. For example,
Each task has a name, which can be used to refer to the task within its owning project, and a fully qualified path, which is unique across all tasks in all projects. The path is the concatenation of the owning project's path and the task's name. Path elements are separated using the {@value org.gradle.api.Project#PATH_SEPARATOR} character. Task ActionsA Groovy closures can also be used to provide a task action. When the action is executed, the closure is called with the task as parameter. You can add action closures to a task by calling There are 2 special exceptions which a task action can throw to abort execution and continue without failing the build. A task action can abort execution of the action and continue to the next action of the task by throwing a org.gradle.api.tasks.StopActionException. A task action can abort execution of the task and continue to the next task by throwing a org.gradle.api.tasks.StopExecutionException. Using these exceptions allows you to have precondition actions which skip execution of the task, or part of the task, if not true. Task Dependencies and Task OrderingA task may have dependencies on other tasks or might be scheduled to always run after another task. Gradle ensures that all task dependencies and ordering rules are honored when executing tasks, so that the task is executed after all of its dependencies and any "must run after" tasks have been executed. Dependencies to a task are controlled using
A
A Plugin may add methods to a By default, tasks are not executed in parallel unless a task is waiting on asynchronous work and another task (which is not dependent) is ready to execute. Parallel execution can be enabled by the |