How to centralize the support libraries dependencies in gradle

Working with multi-modules project, it is very useful to centralize the dependencies, especially the support libraries.

A very good way is to separate gradle build files, defining something like:
In gradleScript/dependecies.gradle:

ext {
    supportLibrary = '22.2.1'

    //Support Libraries dependencies
    supportDependencies = [
            design           :    "${supportLibrary}",
            recyclerView     :    "${supportLibrary}",
            cardView         :    "${supportLibrary}",
            appCompat        :    "${supportLibrary}",
            supportAnnotation:    "${supportLibrary}",
In the top level file build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
    dependencies {
        classpath ''

// Load dependencies
apply from: 'gradleScript/dependencies.gradle'
In the module1/build.gradle:

// Module build file

dependencies {
    compile supportDependencies.appCompat
Here you can find the full gist.

Thanks to Fernando Cejas and this blog.


Post a Comment

Popular posts from this blog

Expand and collapse animation

NotificationListenerService and kitkat

NotificationListenerService and a Whatsapp extension for Dashclock