I don't understand gradle plugins block
apply plugin: 'someplugin1'
apply plugin: 'maven'
and other one:
plugins {
id 'org.hidetake.ssh' version '1.1.2'
}
In first block We have some plugin name. in second one package and version. I don't understand where I should use first block and when second one.
The
plugins
block is the newer method of applying plugins, and they must be available in the Gradle plugin repository. Theapply
approach is the older, yet more flexible method of adding a plugin to your build.The new
plugins
method does not work in multi-project configurations (subprojects
,allprojects
), but will work on the build configuration for each child project.I would think that as functionality progresses, the
plugins
configuration method will overtake the older approach, but at this point both can be and are used concurrently.As already mentioned by @cjstehno the
apply plugin
is a legacy method that you should avoid.With the new
plugins block
method, you can add a plugin and control when to apply it using an optional parameterapply
:You would still use the legacy method in situations where you want to apply an already added but not applied plugin in your
plugins
block. E.g, in the master project a pluginxyz
is added but not applied and it should be applied only in a subprojectsubPro
:Notice that you don't need the version anymore. The version is required in the
plugins
block unless you are using one of the Core Gradle plugins, such asjava
,scala
, ...I spent some time understanding the difference while trying to create a
Spring Boot
application, and that's why I am answering this again after a while. The following example for usingSpring Boot
plugin helped me a lot:What should currently be used:
What had been used before Gradle 2.1: