Grouping dependencies


(Phil Swenson) #1

Does gradle have a way to group a set of dependencies?

For example if I want to declare a dependency on Jetty, I don’t want to have to declare a list of all the Jetty dependencies (list of ~ 20 jars). I would really like to have a way to list all the dependencies associated with jetty somewhere and in gradle simply declare the jetty dependency…

thanks phil


(Gary Hale) #2

You can define a list in a common script and pass it to a dependency declaration anywhere you need it:

def myLibs = ['org.myorg:api:1.0', 'org.myorg:util:2.1']
...
dependencies {
  compile myLibs
}

(Phil Swenson) #3

this helps…

but if you have many projects that want to share this information, it would be useful to publish the “library” to artifactory.

That way an project using a repository could simply declare a dependency on “jetty” and get all the associated dependencies…

does any concept like this exist for gradle?

thanks phil


(Gary Hale) #4

Well, really what you are talking about is common configuration that you want to share between builds and plugins are the mechanism for doing this.  Two ways you can approach it:

  • Add the configuration to a script plugin, publish it to your repository (e.g. artifactory) and then apply it from its http url.
  • Add the configuration to a binary plugin, publish it to your repository and then apply the plugin as a buildscript dependency.
In either case, your plugin can either automatically add the jetty dependencies to your build or just make them available via an extension of some sort so that a project can easily add the jetty libraries with one line.  Depends on what you need/want to do.

Script plugins are more simplistic, but you’ll have to publish them manually and they don’t get cached.  Binary plugins are slightly more involved, but they can be published like any other artifact and they’ll get cached like any other artifact.