# ExtraPropertiesExtension

interface ExtraPropertiesExtension(source)

Additional, ad-hoc, properties for Gradle domain objects.

Extra properties extensions allow new properties to be added to existing domain objects. They act like maps, allowing the storage of arbitrary key/value pairs. All ExtensionAware Gradle domain objects intrinsically have an extension named "{@value #EXTENSION_NAME}" of this type.

An important feature of extra properties extensions is that all of its properties are exposed for reading and writing via the ExtensionAware object that owns the extension.

    project.ext.set("myProp", "myValue")
    assert project.myProp == "myValue"

    project.myProp = "anotherValue"
    assert project.myProp == "anotherValue"
    assert project.ext.get("myProp") == "anotherValue"

Content copied to clipboard
Extra properties extension objects support Groovy property syntax. That is, a property can be read via `extension.«name»` and set via `extension.«name» = "value"`. Wherever possible, the Groovy property syntax should be preferred over the get and set methods.

    project.ext {
      myprop = "a"
    }
    assert project.myprop == "a"
    assert project.ext.myprop == "a"

    project.myprop = "b"
    assert project.myprop == "b"
    assert project.ext.myprop == "b"

Content copied to clipboard
You can also use the Groovy accessor syntax to get and set properties on an extra properties extension.

    project.ext["otherProp"] = "a"
    assert project.otherProp == "a"
    assert project.ext["otherProp"] == "a"

Content copied to clipboard
The exception that is thrown when an attempt is made to get the value of a property that does not exist is different depending on whether the Groovy syntax is used or not. If Groovy property syntax is used, the Groovy groovy.lang.MissingPropertyException will be thrown. When the get method is used, an UnknownPropertyException will be thrown.

## Types

UnknownPropertyException
Link copied to clipboard
open class UnknownPropertyException : InvalidUserDataException
The exception that will be thrown when an attempt is made to read a property that is not set.

## Properties

EXTENSION_NAME
Link copied to clipboard
val EXTENSION_NAME: String = "ext"
The name of this extension in all ExtensionContainers, {@value}.

## Functions

get
Link copied to clipboard
@Nullable
abstract fun get(name: String): @Nullable Any
Returns the value for the registered property with the given name.
getProperties
Link copied to clipboard
abstract fun getProperties(): Map<String, Any>
Returns all of the registered properties and their current values as a map.
has
Link copied to clipboard
abstract fun has(name: String): Boolean
Returns whether or not the extension has a property registered via the given name.
set
Link copied to clipboard
abstract fun set(name: String, @Nullable value: @Nullable Any)
Updates the value for, or creates, the registered property with the given name to the given value.