How to declare multiple dependency with the same group


(黑米仓) #1

Hi, guys ,can gradle declare dependenices which has the same group like below style

compile (‘org.groupname’:[‘nameone’,‘nametow’,‘namethree’,…],‘versionnum’)

or difference version like this:


instead of duplicate declare group or version numbers

(Dimitar Dimitrov) #2

Using a bit of Groovy should do it:

dependencies {
  def fooBundle = [group:, version: '1.2.3']
  compile(['core', 'spi', 'impl'].collect { [module: it] << fooBundle })

Alternatively, you may define the fooBundle in a central location, or decide to use Maven-style BOM’s.

(uklance) #3

If you simply want to define your groups and versions in a single place you can do

ext {
   groups = [foo: 'org.groupname']
   versions = [foo: '1.2.3']
dependencies {
    compile "${}:nameone:${}"
    compile "${}:nametwo:${}"
    compile "${}:namethree:${}"

As @ddimitrov mentioned, Gradle 4.6 added BOM import support which would also solve the problem

(黑米仓) #4

thanks for the good idea,that is a bit usage for me

(黑米仓) #5

Thanks for the soluation ,that looks like a good idea ,guy!