Method for plugins{}

I think every script block has a corresponding method behind it. (Am I right?)
but for the script block:

plugins{...}

I could not find that method.
Can someone help me explain it?

Thanks.

In a build.gradle file, both plugins { ... } and buildscript { ... } are special because they must be evaluated/executed in order to determine the classpath that is used for the execution of the rest of the script. Therefore, you will not find a plugins method in the usual locations.

Instead, Gradle uses an AST library to find these special blocks first and apply them as needed before the rest of the script executes. After the AST transform, the plugins { ... } block itself is applied to the script, which is a PluginsAwareScript. The contents of the block are defined by PluginDependenciesSpec.

1 Like

@jjustinic, thank you for your reply.
When you say “AST”, I thought it is a translation Closure to method call, right?
I think for buildscript { } , there is a java method for project called buildscript​(Closure configureClosure)
So the AST translate this “buildscript{}” to “buildscript method”.
But, I can not find the “plugins” method in anywhere.

I debuged the code and found that the plugins { ... } block is dispatched to the method public void plugins(int lineNumber, Closure configureClosure) of class PluginsAwareScript.

Since you’ve mentioned AST transform, where can I find the source code for AST transform concerning adding a int lineNumber to the plugins { ... } block