Gradle plugin: Convention vs. Extension -


i writing gradle plugin , learning gradle reading user guide , source code of plugins inside gradle project.

in source code, found 2 ways of adding properties project:

  • convention (set javabaseplugin , used javaplugin)
  • extension (set annonceplugin , used buildannouncementsplugin).

i don't understand difference between them , 1 use situation. explain?

ps: add tag "gradle-plugin" in please?

i found answer on forum of gradle:

extensions , conventions similar (but not identical) ways dynamically extend build model. extensions newer concept , have largely replaced conventions. in short, use extensions, don't use conventions.

[...]

an extension instance of arbitrary (typically user-defined) class that's attached build model under user-defined name. extension class can define arbitrary methods. assuming attached project object, extension allows add project.foo.somemethod, not project.somemethod. since each extension has own namespace (foo in case), chance of name collisions reduced (compared conventions).


Comments