What is the internal plumbing for dependencies block?

We recently adopted Gradle and are very pleased with its powerful framework. Being from a pure java world, we start to wonder some internal plumbing of the DSL with Groovy.

For example, in the dependencies block:

dependencies{
compile 'commons-net:commons-net:1.3.0'
......
}

By default, “dependencies” is a method, DefaultProject.dependencies(Closure), which calls ConfigureUtil.configure(Closure configureClosure, T delegate), which in turn to call ClosureBackedAction.execute(). I lost here as “compile” seems not a method for the delegated configuration containers. Is it dynamically created? Where is the code to take care of this? Being from Java world, I guess there is some Groovy magic here. What is it?

Generally, I would appreciate if there is some general guide about how to read the Gradle source code. I was able to generate a IntelliJ project on it using gradle and to import the whole project into the IDE. But it would still be nice if I can find some general description about the internal structure of different packages/subprojects and other basic information. For example, how to set a simple run configuration in IDE to run a simple test, where I can set some break points in debugging mode and learn more? Thanks.

The ‘dependencies {…}’ configuration closure delegates to an instance of ‘DependencyHandler’. The best way to find this out is to look at the “Delegates to” portion of the DSL Reference.

You might notice, there is no ‘compile()’ method defined for that class. This is done with some Groovy magic by implementing the ‘methodMissing()’ method, which is called whenever a call is made to an undefined method. This specific implementation then looks for a configuration with the same name of the method called. In your example above, Gradle will throw a ‘MissingMethodException’ if a configuration with the name “compile” doesn’t exist (for example, if you forgot to apply the java plugin).

For your last question, if you are using IntelliJ IDEA, running ‘gradlew idea’ will additionally create some run configurations for you.