You can declare common dependencies in the parent script:
ext.libraries = [ // Groovy map literal spring_core: "org.springframework:spring-core:3.1", junit: "junit:junit:4.10" ]
From a child script, you can use dependency declarations as follows:
dependencies { compile libraries.spring_core testCompile libraries.junit }
To separate dependency declarations with advanced configuration options, you can use DependencyHandler.create :
libraries = [ spring_core: dependencies.create("org.springframework:spring-core:3.1") { exclude module: "commons-logging" force = true } ]
Several dependencies can be shared under the same name:
libraries = [ spring: [ // Groovy list literal "org.springframework:spring-core:3.1", "org.springframework:spring-jdbc:3.1" ] ]
dependencies { compile libraries.spring } will then add both dependencies at once.
The only information you cannot use in this way is the configuration (scope in terms of Maven) to which the dependency should be assigned. However, in my experience, itβs better to be explicit anyway.
Peter Niederwieser Mar 03 '12 at 16:15 2012-03-03 16:15
source share