I am writing a Gradle plugin and I am learning Gradle by reading the user guide and the source code of the plugins inside the Gradle project.
In the source code, I found 2 ways of adding properties to the project:
I don't understand the difference between them and which one to use for which situation. Could someone explain?
PS: Could someone add the tag "gradle-plugin" in SO please?
I found an answer on the forum of Gradle:
Extensions and conventions are similar (but not identical) ways to dynamically extend the build model. Extensions are the newer concept and have largely replaced conventions. In short, only use extensions, don't use conventions.
[...]
An extension is an instance of an arbitrary (typically user-defined) class that's attached to the build model under a user-defined name. The extension class can define arbitrary methods. Assuming it is attached to a Project object, an extension allows you to add project.foo.someMethod, but not project.someMethod. Since each extension has its own namespace (foo in this case), the chance of name collisions is greatly reduced (compared to conventions).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With