Gradle - specifying configuration based dependency

While reading this gradle document, I came across this wordings saying that dependencies for each configuration. Here what does this configuration meant to be. Because I usually used to specify the dependencies in such a vague way like

dependencies {
    compile 'org.springframework:spring-core:4.0.5.RELEASE',
            'org.hibernate:hibernate-core:3.6.7.Final'
}

Is there any other possible way to specify the dependencies(based on configuration)?. I am little curious to know about that.

If yes, what is advantage of specifying dependencies like that. Can someone able to throw some light here?

Also how the below command will be useful?

gradle -q dependencies api:dependencies webapp:dependencies

Upvotes: 0

Views: 78

Answers (1)

AdamSkywalker
AdamSkywalker

Reputation: 11619

In Gradle dependencies are grouped into configurations. Configurations have a name, a number of other properties, and they can extend each other. Many Gradle plugins add pre-defined configurations to your project.

These are the configurations added by Java plugin. As you can see, compile is a configuration, it is extended by many other configurations. You can create your own configuration:

configurations {
    myConfig {
        description = 'my config'
        transitive = true
        extendsFrom compile
    }
}

Also how the below command will be useful?

This command prints the dependencies of main project and api and webapp subprojects.

Upvotes: 1

Related Questions