Table of Contents
| API Documentation: | PluginManager |
|---|
Facilitates applying plugins and determining which plugins have been applied to a PluginAware object.
| Method | Description |
apply(type) | Applies the given plugin. Does nothing if the plugin has already been applied. |
apply(pluginId) | Applies the plugin with the given ID. Does nothing if the plugin has already been applied. |
findPlugin(id) | Returns information about the plugin with the given ID that has been applied or is currently being applied, or null if there is no such plugin. |
hasPlugin(id) | Returns |
withPlugin(id, action) | Executes the given action when the specified plugin is applied. |
void apply(Class<?> type)
Class<?>Applies the given plugin. Does nothing if the plugin has already been applied.
The given class should implement the Plugin interface, and be parameterized for a compatible type of this.
The following two lines are equivalent…
pluginManager.apply org.gradle.api.plugins.JavaPlugin
pluginManager.apply "org.gradle.java"
void apply(String pluginId)
Applies the plugin with the given ID. Does nothing if the plugin has already been applied.
Plugins in the "org.gradle" namespace can be applied directly via name.
That is, the following two lines are equivalent…
pluginManager.apply "org.gradle.java" pluginManager.apply "java"
AppliedPlugin findPlugin(String id)
Returns information about the plugin with the given ID that has been applied or is currently being applied, or null if there is no such plugin.
Plugins in the "org.gradle" namespace (that is, core Gradle plugins) can be specified by either name (e.g. "java") or ID "org.gradle.java".
All other plugins must be queried for by their full ID (e.g. "org.company.some-plugin").
Some Gradle plugins have not yet migrated to fully qualified plugin IDs.
Such plugins can be detected with this method by simply using the unqualified ID (e.g. "some-third-party-plugin".
boolean hasPlugin(String id)
Returns true if a plugin with the given ID has already been applied or is currently being applied, otherwise false.
In contrast, PluginManager.withPlugin(java.lang.String, org.gradle.api.Action) and PluginContainer.hasPlugin(java.lang.String) only consider a plugin once its application has completed.
void withPlugin(String id, Action<? super AppliedPlugin> action)
Action<? super AppliedPlugin>Executes the given action when the specified plugin is applied.
If a plugin with the specified ID has already been applied, the supplied action will be executed immediately. Otherwise, the action will executed immediately after a plugin with the specified ID is applied.
The given action is always executed after the plugin has been applied.