MapProperty (Gradle API 9.1.0)
Description: declaration: package: org.gradle.api.provider, interface: MapProperty

Package org.gradle.api.provider

# Interface MapProperty<K,V>

Type Parameters:
  `K` - the type of keys.
  `V` - the type of values.

All Superinterfaces:
  `HasConfigurableValue`, `Provider<Map<K,V>>`, `SupportsConvention`

@ManagedType @SupportsKotlinAssignmentOverloading public interface MapProperty<K,V> extends Provider<Map<K,V>>, HasConfigurableValue, SupportsConvention
Represents a property whose type is a `Map` of keys of type `MapProperty` and values of type `MapProperty`. Retains iteration order.

Instances of this interface are not thread-safe for reading and writing. It is not safe to share the same MapProperty instance between different projects.

Note: This interface is not intended for implementation by build script or plugin authors.

Since:
  5.1
See Also:
  - `Create an instance of this as a managed property (preferred).`
  - `Create an instance of this manually.`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `MapProperty<K,V>`
  `convention(@Nullable Map<? extends K,? extends V> value)`
  Specifies the value to use as the convention for this property.
  `MapProperty<K,V>`
  `convention(Provider<? extends Map<? extends K,? extends V>> valueProvider)`
  Specifies the provider of the value to use as the convention for this property.
  `MapProperty<K,V>`
  `empty()`
  Sets the value of this property to an empty map, and replaces any existing value.
  `void`
  `finalizeValue()`
  Disallows further changes to the value of this property.
  `Provider<V>`
  `getting(K key)`
  Returns a provider that resolves to the value of the mapping of the given key.
  `Provider<Set<K>>`
  `keySet()`
  Returns a `Provider` that returns the set of keys for the map that is the property value.
  `void`
  `put(K key, Provider<? extends V> providerOfValue)`
  Adds a map entry to the property value.
  `void`
  `put(K key, V value)`
  Adds a map entry to the property value.
  `void`
  `putAll(Map<? extends K,? extends V> entries)`
  Adds all entries from another `Map` to the property value.
  `void`
  `putAll(Provider<? extends Map<? extends K,? extends V>> provider)`
  Adds all entries from another `Map` to the property value.
  `void`
  `set(@Nullable Map<? extends K,? extends V> entries)`
  Sets the value of this property to the entries of the given Map, and replaces any existing value.
  `void`
  `set(Provider<? extends Map<? extends K,? extends V>> provider)`
  Sets the property to have the same value of the given provider, and replaces any existing value.
  `MapProperty<K,V>`
  `unset()`
  Unsets this object's explicit value, allowing the convention to be selected when evaluating this object's value.
  `MapProperty<K,V>`
  `unsetConvention()`
  Unsets this object's convention value.
  `MapProperty<K,V>`
  `value(@Nullable Map<? extends K,? extends V> entries)`
  Sets the value of this property to the entries of the given Map, and replaces any existing value.
  `MapProperty<K,V>`
  `value(Provider<? extends Map<? extends K,? extends V>> provider)`
  Sets the property to have the same value of the given provider, and replaces any existing value.

  ### Methods inherited from interface org.gradle.api.provider.HasConfigurableValue

  `disallowChanges, disallowUnsafeRead, finalizeValueOnRead`

  ### Methods inherited from interface org.gradle.api.provider.Provider

  `filter, flatMap, get, getOrElse, getOrNull, isPresent, map, orElse, orElse, zip`

- ## Method Details

  - ### empty

    MapProperty<K,V> empty()
    Sets the value of this property to an empty map, and replaces any existing value.
    Returns:
      this property.

  - ### getting

    Provider<V> getting(K key)
    Returns a provider that resolves to the value of the mapping of the given key. It will have no value if the property has no value, or if it does not contain a mapping for the key.

    The returned provider tracks changes to this property and resolves its value dynamically when queried. It also inherits the task dependencies of all entries in the map, if any.

    This method is equivalent to

             map(m -> m.get(key))

    but possibly more efficient.
    Parameters:
      `key` - the key
    Returns:
      a `Provider` for the value

  - ### set

    void set(@Nullable Map<? extends K,? extends V> entries)
    Sets the value of this property to the entries of the given Map, and replaces any existing value. This property will query the entries of the map each time the value of this property is queried.

    This method can also be used to discard the value of the property, by passing `null` as the value. The convention for this property, if any, will be used to provide the value instead.

    Parameters:
      `entries` - the entries, can be `null`

  - ### set

    void set(Provider<? extends Map<? extends K,? extends V>> provider)
    Sets the property to have the same value of the given provider, and replaces any existing value. This property will track the value of the provider and query its value each time the value of this property is queried. When the provider has no value, this property will also have no value.
    Parameters:
      `provider` - Provider of the entries.

  - ### value

    MapProperty<K,V> value(@Nullable Map<? extends K,? extends V> entries)
    Sets the value of this property to the entries of the given Map, and replaces any existing value. This property will query the entries of the map each time the value of this property is queried.

    This is the same as `set(Map)` but returns this property to allow method chaining.

    Parameters:
      `entries` - the entries, can be `null`
    Returns:
      this
    Since:
      5.6

  - ### value

    MapProperty<K,V> value(Provider<? extends Map<? extends K,? extends V>> provider)
    Sets the property to have the same value of the given provider, and replaces any existing value. This property will track the value of the provider and query its value each time the value of this property is queried. When the provider has no value, this property will also have no value.

    This is the same as `set(Provider)` but returns this property to allow method chaining.

    Parameters:
      `provider` - Provider of the entries.
    Since:
      5.6

  - ### put

    void put(K key, V value)
    Adds a map entry to the property value.
    Parameters:
      `key` - the key
      `value` - the value

  - ### put

    void put(K key, Provider<? extends V> providerOfValue)
    Adds a map entry to the property value.

    The given provider will be queried when the value of this property is queried. This property will have no value when the given provider has no value.

    Parameters:
      `key` - the key
      `providerOfValue` - the provider of the value

  - ### putAll

    void putAll(Map<? extends K,? extends V> entries)
    Adds all entries from another `Map` to the property value.
    Parameters:
      `entries` - a `Map` containing the entries to add

  - ### putAll

    void putAll(Provider<? extends Map<? extends K,? extends V>> provider)
    Adds all entries from another `Map` to the property value.

    The given provider will be queried when the value of this property is queried. This property will have no value when the given provider has no value.

    Parameters:
      `provider` - the provider of the entries

  - ### keySet

    Provider<Set<K>> keySet()
    Returns a `Provider` that returns the set of keys for the map that is the property value.

    The returned provider tracks changes to this property and resolves its value dynamically when queried. It also inherits the task dependencies of all entries in the map, if any.

    This method is equivalent to

             map(m -> m.keySet())

    but possibly more efficient.
    Returns:
      a `Provider` that provides the set of keys for the map

  - ### convention

    MapProperty<K,V> convention(@Nullable Map<? extends K,? extends V> value)
    Specifies the value to use as the convention for this property. The convention is used when no value has been set for this property.
    Parameters:
      `value` - The value, or `null` when the convention is that the property has no value.
    Returns:
      this

  - ### convention

    MapProperty<K,V> convention(Provider<? extends Map<? extends K,? extends V>> valueProvider)
    Specifies the provider of the value to use as the convention for this property. The convention is used when no value has been set for this property.
    Parameters:
      `valueProvider` - The provider of the value.
    Returns:
      this

  - ### unset

    @Incubating MapProperty<K,V> unset()
    Unsets this object's explicit value, allowing the convention to be selected when evaluating this object's value.

    This is similar to calling `value(Map)` with a `null` argument.

    Specified by:
      `unset` in interface `SupportsConvention`

  - ### unsetConvention

    @Incubating MapProperty<K,V> unsetConvention()
    Unsets this object's convention value.

    This is similar to calling `convention(Map)` with a `null` argument.

    Specified by:
      `unsetConvention` in interface `SupportsConvention`

  - ### finalizeValue

    void finalizeValue()
    Disallows further changes to the value of this property. Calls to methods that change the value of this property, such as `set(Map)` or `put(Object, Object)` will fail.

    When this property has elements provided by a `Provider`, the value of the provider is queried when this method is called and the value of the provider will no longer be tracked.

    Note that although the value of the property will not change, the resulting map may contain mutable objects. Calling this method does not guarantee that the value will become immutable.

    Specified by:
      `finalizeValue` in interface `HasConfigurableValue`