5

Is there a good pattern to reuse dependency blocks in gradle? at the moment there is a lot of repetition ( same blocks in different modules - application / tests / .. ) Is there a way to define these dependencies in a central place and reuse them in the modules?

ligi
  • 39,001
  • 44
  • 144
  • 244

1 Answers1

6

You can group dependencies into a list for instance and the pass this list for given configuration:

apply plugin: 'java'

repositories {
    mavenCentral()
}

ext.forDI = [
    'com.google.inject:guice:3.0',
    'com.google.guava:guava:18.0'
]

dependencies {
    compile(forDI)
}

This question might be also helpful for you and this as well.

Community
  • 1
  • 1
Opal
  • 81,889
  • 28
  • 189
  • 210
  • thanks! this is a good start - unfortunately this does not really work when you have exclusions and stuff - hope there will be a nicer way ( I am thinking more about extending dependencies ) - but if not - I will accept this answer – ligi Jan 27 '15 at 11:23
  • I guess it might be better solution - since groovy + gradle is a really flexible pair - but more advanced example is need to find a better solution. – Opal Jan 27 '15 at 11:35