# Interface PluginContainer

All Superinterfaces:
  `Collection<Plugin>, DomainObjectCollection<Plugin>, DomainObjectSet<Plugin>, Iterable<Plugin>, PluginCollection<Plugin>, Set<Plugin>`

public interface PluginContainer extends PluginCollection<Plugin>

A `PluginContainer` is used to manage a set of `Plugin` instances applied to a particular project.

Plugins can be specified using either an id or type. The id of a plugin is specified using a META-INF/gradle-plugins/${id}.properties classpath resource.

Since:
  0.7

- ## Method Summary

  Modifier and Type
  Method
  Description
  `<T extends Plugin>
  T`
  `apply(Class<T> type)`
  Applies a plugin to the project.
  `Plugin`
  `apply(String id)`
  Has the same behavior as `apply(Class)` except that the plugin is specified via its id.
  `<T extends Plugin>
  @Nullable T`
  `findPlugin(Class<T> type)`
  Returns the plugin for the given type.
  `@Nullable Plugin`
  `findPlugin(String id)`
  Returns the plugin for the given id.
  `<T extends Plugin>
  T`
  `getAt(Class<T> type)`
  Returns a plugin with the specified type if this plugin has been used in the project.
  `Plugin`
  `getAt(String id)`
  Returns a plugin with the specified id if this plugin has been used in the project.
  `<T extends Plugin>
  T`
  `getPlugin(Class<T> type)`
  Returns a plugin with the specified type if this plugin has been used in the project.
  `Plugin`
  `getPlugin(String id)`
  Returns a plugin with the specified id if this plugin has been used in the project.
  `boolean`
  `hasPlugin(Class<? extends Plugin> type)`
  Returns true if the container has a plugin with the given type, false otherwise.
  `boolean`
  `hasPlugin(String id)`
  Returns true if the container has a plugin with the given id, false otherwise.
  `void`
  `withId(String pluginId, Action<? super Plugin> action)`
  Executes or registers an action for a plugin with given id.

  ### Methods inherited from interface Collection

  `parallelStream, removeIf, stream, toArray`

  ### Methods inherited from interface DomainObjectCollection

  `addAllLater, addLater, all, all, configureEach, disallowChanges, getElements, whenObjectAdded, whenObjectAdded, whenObjectRemoved, whenObjectRemoved, withType, withType`

  ### Methods inherited from interface DomainObjectSet

  `findAll`

  ### Methods inherited from interface Iterable

  `forEach`

  ### Methods inherited from interface PluginCollection

  `add, addAll, clear, matching, matching, remove, removeAll, whenPluginAdded, whenPluginAdded, withType`

  ### Methods inherited from interface Set

  `contains, containsAll, equals, hashCode, isEmpty, iterator, retainAll, size, spliterator, toArray, toArray`

- ## Method Details

  - ### apply

    Plugin apply(String id)
    Has the same behavior as `apply(Class)` except that the plugin is specified via its id. Not all plugins have an id.
    Parameters:
      `id` - The id of the plugin to be applied.
    Returns:
      The plugin which has been used against the project.
    Since:
      0.9

  - ### apply

    <T extends Plugin> T apply(Class<T> type)
    Applies a plugin to the project. This usually means that the plugin uses the project API to add and modify the state of the project. This method can be called an arbitrary number of times for a particular plugin type. The plugin will be actually used only the first time this method is called.
    Parameters:
      `type` - The type of the plugin to be used
    Returns:
      The plugin which has been used against the project.
    Since:
      0.9

  - ### hasPlugin

    boolean hasPlugin(String id)
    Returns true if the container has a plugin with the given id, false otherwise.
    Parameters:
      `id` - The id of the plugin
    Since:
      0.7

  - ### hasPlugin

    boolean hasPlugin(Class<? extends Plugin> type)
    Returns true if the container has a plugin with the given type, false otherwise.
    Parameters:
      `type` - The type of the plugin
    Since:
      0.7

  - ### findPlugin

    @Nullable Plugin findPlugin(String id)
    Returns the plugin for the given id.
    Parameters:
      `id` - The id of the plugin
    Returns:
      the plugin or null if no plugin for the given id exists.
    Since:
      0.7

  - ### findPlugin

    <T extends Plugin> @Nullable T findPlugin(Class<T> type)
    Returns the plugin for the given type.
    Parameters:
      `type` - The type of the plugin
    Returns:
      the plugin or null if no plugin for the given type exists.
    Since:
      0.7

  - ### getPlugin

    Plugin getPlugin(String id) throws UnknownPluginException
    Returns a plugin with the specified id if this plugin has been used in the project.
    Parameters:
      `id` - The id of the plugin
    Throws:
      `UnknownPluginException` - When there is no plugin with the given id.
    Since:
      0.9

  - ### getPlugin

    <T extends Plugin> T getPlugin(Class<T> type) throws UnknownPluginException
    Returns a plugin with the specified type if this plugin has been used in the project.
    Parameters:
      `type` - The type of the plugin
    Throws:
      `UnknownPluginException` - When there is no plugin with the given type.
    Since:
      0.9

  - ### getAt

    Plugin getAt(String id) throws UnknownPluginException
    Returns a plugin with the specified id if this plugin has been used in the project. You can use the Groovy `[]` operator to call this method from a build script.
    Parameters:
      `id` - The id of the plugin
    Throws:
      `UnknownPluginException` - When there is no plugin with the given id.
    Since:
      0.9

  - ### getAt

    <T extends Plugin> T getAt(Class<T> type) throws UnknownPluginException
    Returns a plugin with the specified type if this plugin has been used in the project. You can use the Groovy `[]` operator to call this method from a build script.
    Parameters:
      `type` - The type of the plugin
    Throws:
      `UnknownPluginException` - When there is no plugin with the given type.
    Since:
      0.9

  - ### withId

    void withId(String pluginId, Action<? super Plugin> action)
    Executes or registers an action for a plugin with given id. If the plugin was already applied, the action is executed. If the plugin is applied sometime later the action will be executed after the plugin is applied. If the plugin is never applied, the action is never executed. The behavior is similar to `DomainObjectCollection.withType(Class, org.gradle.api.Action)`.
    Parameters:
      `pluginId` - the id of the plugin
      `action` - the action
    Since:
      2.0