From the above build.gradle file I understand that dependencies is a script block (a method which takes a closure as a parameter). It is defined in the Project object.
The compile is a so called configuration. It is defined in the Java plug in. Is it also a method which takes one argument as a parameter? How it affects the dependencies script block or the overall build in this case?
It’s probably best to first understand the domain model before looking at the Groovy specific items.
The Project has a ConfigurationContainer which can contain any number of configurations. A Configuration contains any Dependency that might be needed for a particular usage. In the case of compile, it’s part of a hierarchy introduced by the Java plugin (see diagram) that will minimally be used by tasks created by the same plugin.
The dependencies block is dealing with a DependencyHandler, which has methods such as:
The DependencyHandler is orchestrating adding the dependency to the correct Configuration from the ConfigurationContainer. However, calling these methods directly doesn’t make for a nice looking DSL. There is no actual compile method, but there is dynamic behavior that treats the method name as the configuration and delegates to the appropriate call.