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:
root
  --gradleScript
  ----dependencies.gradle
  --module1
  ----build.gradle
  --build.gradle
In gradleScript/dependecies.gradle:

ext {
    //Version
    supportLibrary = '22.2.1'

    //Support Libraries dependencies
    supportDependencies = [
            design           :    "com.android.support:design:${supportLibrary}",
            recyclerView     :    "com.android.support:recyclerview-v7:${supportLibrary}",
            cardView         :    "com.android.support:cardview-v7:${supportLibrary}",
            appCompat        :    "com.android.support:appcompat-v7:${supportLibrary}",
            supportAnnotation:    "com.android.support:support-annotations:${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 {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

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

// Module build file

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

Thanks to Fernando Cejas and this blog.

Comments

  1. Very Nice Blog, You are spreading very good information among us… Yes Web Hosting plays very important role in business world. And it is important to have the best hosting services.
    Germany VPS Hosting

    ReplyDelete
  2. This Article is Worth of sharing. The information is helpful for sure! Keep going like this!
    Germany VPS Hosting

    ReplyDelete
  3. Am really impressed about this blog because this blog is very easy to learn and understand clearly.This blog is very useful for the college students and researchers to take a good notes in good manner,I gained many unknown information.
    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training

    ReplyDelete
  4. Thanks for provide great informatics and looking beautiful blog, really nice required information & the things i never imagined and i would request, wright more blog and blog post like that for us. Thanks you
    DevOps Training in Chennai

    DevOps Online Training in Chennai

    DevOps Training in Bangalore

    DevOps Training in Hyderabad

    DevOps Training in Coimbatore

    DevOps Training

    DevOps Online Training

    ReplyDelete
  5. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    best machine learning course online
    learn machine learning online
    Machine Learning Online training hyderabad

    ReplyDelete
  6. Stay Home And Be safe Carona effect Nice to see your blog keep updating offers & coupons Clovia Coupons and Offers- Find the latest Filpkart, Nykaa, nnnow, paytmall, Clovia Coupons and Best Offers for Men & women online shopping at Tracedeals.
    Amazon offers
    Clovia offers
    Flipkart offers
    Nykaa offers
    Nnnow offers
    Paytmmall offers
    oppo Mobile offers
    Samsung Mobile Phone
    Flipkart Coupons
    Flipkart sale
    Bookmyshow Coupons

    ReplyDelete

Post a Comment

Popular posts from this blog

Expand and collapse animation

NotificationListenerService and kitkat

NotificationListenerService and a Whatsapp extension for Dashclock