amorfis
amorfis

Reputation: 15770

Group and reuse dependencies in gradle multiproject build

I have multiproject build in gradle. In build.gradle I have some dependencies the same for two or more projects:

project(":pr-common") {
  dependencies {
    compile "joda-time:joda-time:2.3"
    compile "org.joda:joda-convert:1.6"
  }
}

project(":pr-domain") {
  dependencies {
    compile "joda-time:joda-time:2.3"
    compile "org.joda:joda-convert:1.6"
  }
}

Can I somehow group and reuse this dependencies? I want something like this:

def joda = [
  compile "joda-time:joda-time:2.3", 
  compile "org.joda:joda-convert:1.6"
]

project(":pr-common") {
  dependencies {
    joda
  }
}

project(":pr-domain") {
  dependencies {
    joda
  }
}

Upvotes: 3

Views: 634

Answers (1)

Opal
Opal

Reputation: 84756

You can't reuse dependencies in the way You suggested. Instead, You can use the following piece of code.

build.gradle (root project)

subprojects.findAll { it.path.contains('pr') }.each { //whatever search condition
   it.plugins.apply 'groovy'

   it.dependencies {
      compile 'com.google.inject:guice:3.0'
      compile 'com.google.guava:guava:15.0'
   }
}

Upvotes: 1

Related Questions