What is the connection between dependencies and configurations?

(Tomas Michael) #1

Hello. I am totally new to Gradle (and Groovy syntax) so I have difficulties understanding some concepts.

One of them are dependencies and configurations.

apply plugin: 'java'

repositories {

dependencies {
    compile 'org.springframework:spring-core:4.1.1.RELEASE'

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?

(James Justinic) #2

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:

add(String configurationName, Object dependencyNotation)`

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.

(Tomas Michael) #3

Answer here. https://stackoverflow.com/questions/50042746/gradle-what-is-the-connection-between-dependencies-and-configurations