API Documentation: | PluginDependenciesSpec |
---|
Note: This class is incubating and may change in a future version of Gradle.
The DSL for declaring plugins to use in a script.
In a build script, the plugins {}
script block API is of this type.
That is, you can use this API in the body of the plugins script block to declare plugins to be used for the script.
The plugins {}
block serves a similar purpose to the PluginAware.apply()
method
that can be used to apply a plugin directly to a Project
object or similar.
A key difference is that plugins applied via the plugins {}
block are conceptually applied to the script, and by extension the script target.
At this time there is no observable practical difference between the two approaches with regard to the end result.
The plugins {}
block is a new, incubating, Gradle feature that will evolve to offer benefits over the apply()
approach.
The plugins {}
block only allows a strict subset of the full build script programming language.
Only the API of this type can be used, and values must be literal (e.g. constant strings, not variables).
Moreover, the plugins {}
block must be the first code of a build script.
There is one exception to this, in that the buildscript {
} block (used for declaring script dependencies) must precede it.
This implies the following constraints:
- Only
PluginDependenciesSpec.id()
method calls may be top level statements PluginDependenciesSpec.id()
calls may only be followed by aPluginDependencySpec.version()
method call on the returned objectPluginDependenciesSpec.id()
andPluginDependencySpec.version()
methods must be called with a literal literal argument (i.e. not a variable)- The
plugins {}
script block must follow anybuildscript {}
script block, but must precede all other logic in the script
Core Gradle plugins are able to be applied using the plugins {}
block.
Core plugins must be specified without a version number, and can have a qualified or unqualified id.
That is, the java
plugin can be used via:
plugins {
id 'java'
}
Or via:
plugins {
id 'org.gradle.java'
}
Core Gradle plugins use the org.gradle
namespace.
For the list of available core plugins for a particular Gradle version, please consult the User Guide.
Non-core plugins are available from the Gradle Plugin Portal. These plugins are contributed by users of Gradle to extend Gradle's functionality. Visit plugins.gradle.org to browse the available plugins and versions.
To use a community plugin, the fully qualified id must be specified along with a version.
Method | Description |
id(id) | Incubating Add a dependency on the plugin with the given id. |
PluginDependencySpec
id
(String
id)
Note: This method is incubating and may change in a future version of Gradle.
Add a dependency on the plugin with the given id.
plugins {
id "org.company.myplugin"
}
Further constraints (e.g. version number) can be specified by the methods of the return value.
plugins { id "org.company.myplugin" version "1.3" }