I am applying plugins to a Gradle build script. But there happen to be many ways to doing this.
I found the following two methods for applying plugins to a Gradle project:
The DSL for declaring plugins to use in a script i.e.
plugins {}script block, which I think configures aPluginDependenciesSpecobject. (Read this)- Why isn't the
plugins {}script block shown in the Script blocks section of theProjectDSL documentation?
- Why isn't the
Calling
pluginManager.apply()(which applies plugins to aPluginManagerinstance) or callingplugins.apply()(which applies plugins to aPluginContainerinstance) (Read this)
So for applying, say org.gradle.java plugin, I could do the following in a build.gradle file:
>> pluginManager.apply 'org.gradle.java'
>> plugins.apply 'org.gradle.java'
>> plugins {
id 'org.gradle.java'
}
What are the differences between each?
PS: I found this in the documentation for PluginDependenciesSpec, but then why have so many different methods?
The plugins {} block serves a similar purpose to the PluginAware.apply(java.util.Map) 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.