0

In the following example, I have 3 dependencies with the same group and the same version. I want to group these three dependencies in one line.

compile group: 'org.apache.ws.commons.axiom', name: 'axiom-api', version: '1.2.7'
compile group: 'org.apache.ws.commons.axiom', name: 'axiom-dom', version: '1.2.7'
compile group: 'org.apache.ws.commons.axiom', name: 'axiom-impl', version: '1.2.7'

Expected like below

group("axiom-api", "axiom-dom", "axiom-impl", :under=>"org.apache.ws.commons.axiom", :version=>"1.2.7")

Is it possible in gradle?

Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
  • 1
    Could you provide an example of how you expect it to look like? I don't see no point in formatting it in one line. You could/should however use a variable for the version number to keep the versions always in sync. – dpr Jul 28 '20 at 15:44
  • @dpr I have updated my question with my expectation. – Sathiamoorthy Jul 28 '20 at 15:49
  • As you have same version, to find the optimum, try this useful suggestion https://stackoverflow.com/a/30649660/13031115 – MdBasha Jul 28 '20 at 16:58

2 Answers2

1

Well it's actually more lines in total, but if this (same group, same version and multiple artifacts) is a repeating pattern, it might still be handy:

def groupDependencies ( group, names, version ) {
  def deps = []
  names.each { it -> 
    deps += [group: group, name: it, version: version]
  }

  return deps
}

dependencies {
  compile(groupDependencies('org.apache.ws.commons.axiom', ['axiom-api', 'axiom-dom', 'axiom-impl'], '1.2.7'))
}
Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
dpr
  • 10,591
  • 3
  • 41
  • 71
0

This is an example where you can add different artifacts each with a different version.

def groupDependencies (group, artifact) {
    def dependencies = []

    artifact.each { it ->
        dependencies += [group: group, name: it["name"], version: it["version"]]
    }

    return dependencies
}

dependencies {
    implementation(groupDependencies("org.apache.commons", [
            [name: "commons-lang3", version: "3.12.0"],
            [name: "commons-collections4", version: "4.4"],
            [name: "commons-compress", version: "1.21"]
    ]))
}

And this other is for when the group and the name is the same (you can use them both on the same file):

def groupDependencies (artifact) {
    def dependencies = []

    artifact.each { it ->
        dependencies += [group: it["name"], name: it["name"], version: it["version"]]
    }

    return dependencies
}

dependencies {
    implementation(groupDependencies([
            [name: "commons-cli", version: "1.5.0"],
            [name: "commons-io", version: "2.11.0"]
    ]))
}