Where should I use plugins?

I see the documentation that plugins can use in build.gradle and settings.gradle.
This is my question.
What is different between two files and How can I choose where plugins put in?

Usually, not you choose, but the plugin implementor.
There are also init scripts where also plugins can be implemented.
But the typical plugin you will use is for application in the build script, not in the settings script.

What the difference is between the files, I recommend you have a look at the documentation.
Broadly summarized, in the settings script you define some project-wide things like build cache configuration and which projects are part of the build, in the build scripts you define the actual projects you build.

Btw., I highly recommend using Kotin DSL, not Groovy DSL. By now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio.

Thank you for answering.
You say typically use plugins in build script, then when we use plugins in settings script?
Could you tell me that situation?

As I said, the author of the plugin decides where it can be applied.
Settings plugins do things that you would do in a settings script.
Project plugins do thing that you would do in a build script.
For example the foojay resolver convention plugin is a settings plugin.

From your comment, I would not use plugins often in settings script.
Thank you.

1 Like