Gradle snippets: extract your dependencies

I believe you’ll find this in every gradle project you can download from the net. Since it’s groovy it’s best to just declare a map with your external dependencies in root project. You can then use it in your subprojects just by accessing a key from map.

Let’s see a sample configuration:

// def versions would create script local variable
versions = [
        camel: "2.5.0"
]

libraries = [
        camel: [group:"org.apache.camel", name:"camel-core", version:versions.camel],
        camelBindy: "org.apache.camel:camel-bindy:${versions.camel}"
]

You can see two maps actually: versions and variables.
First one defines versions used for particular libraries. Since camel version is used in multiple places, you can just extract it and keep outside the libraries definitions.
Libraries is a map of our dependencies.

Usage is also simple:

// somewhere in root project or subprojects
dependencies {
  compile libraries.camel
  compile libraries.camelBindy
}
Tagged with: , , ,
Posted in gradle snippets

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>