1

I'm junior currently learning gradle and groovy. this is what the book I'm reading says during wrtten build.gradle

apply plugin: 'java'
apply plugin: 'application'

However, the build.gradle in the project created by the spring-initalizer use the following syntax:

plugins {
    id 'org.springframework.boot' version '2.4.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

I know they're both working normally, but I wonder exactly what the difference is. And which grammar do you recommend in general?

Thank you very much for watching my poor question through, and I hope you have a good day.

shirohoo
  • 91
  • 7
  • 1
    Does this answer your question? [What the difference in applying gradle plugin](https://stackoverflow.com/questions/32352816/what-the-difference-in-applying-gradle-plugin) – Reza Ebrahimpour Jun 01 '21 at 05:28

1 Answers1

2

Based on the documentation, using the apply method is a traditional and legacy mechanism to apply a plugin, and they suggest not use this method anymore. So, the suggested mechanism is using the plugins block.

Applying plugins with the plugins DSL:

There are some key differences between the plugins {} block mechanism and the “traditional” apply() method mechanism. There are also some constraints, some of which are temporary limitations while the mechanism is still being developed and some are inherent to the new approach.

Legacy Plugin Application:

With the introduction of the plugins DSL, users should have little reason to use the legacy method of applying plugins.

Read more on Gradle documentation: https://docs.gradle.org/current/userguide/plugins.html

Reza Ebrahimpour
  • 814
  • 6
  • 20