Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: "apply plugin" at the top or at the bottom

Has the same effect add the "apply plugin" at the beginning or end of the file build.gradle in Android Studio projects?

For example to add the 'com.google.gms.google-services' plugin, Firebase official documentation recommends adding at the end, but I've seen other codes add it at the beginning.

I know the question seems irrelevant, but I'm developing a plugin for Android Studio to manage dependencies and have this doubt.

Apply Plugin botton or top

Thanks in advance

like image 415
Hector Oliveros Avatar asked Sep 22 '16 14:09

Hector Oliveros


People also ask

Where do I put plugins in build Gradle?

Put the source of the plugin directly into the build. gradle file. One big advantage of this approach is that the class is automatically compiled and added to the classpath of the build script without you configuring anything.

How does apply plugin work in Gradle?

Applying a plugin to a project allows the plugin to extend the project's capabilities. It can do things such as: Extend the Gradle model (e.g. add new DSL elements that can be configured) Configure the project according to conventions (e.g. add new tasks or configure sensible defaults)

What is plugin base in Gradle?

The Base Plugin provides some tasks and conventions that are common to most builds and adds a structure to the build that promotes consistency in how they are run.


1 Answers

Gradle scripts are interpreted top to bottom so order can be important. Keep in mind that gradle has a configuration phase and an execution phase so sometimes order isn't important. It's common to apply your plugins at the top of the script since plugins often add extension objects and tasks to the gradle model which can then be configured lower down in the build script.

For example, you can't do the following because the test task is added by the java plugin:

test {
   include 'org/foo/**'
}
apply plugin: 'java'
like image 192
lance-java Avatar answered Oct 16 '22 16:10

lance-java