Member-only story
Better Dependency Management Using buildSrc + Kotlin DSL
Dependency management for better reusability and easy maintenance

Introduction
Since the start of using Android Studio, Gradle has become a central place for managing many things like dependencies, config data, flavours, etc. And maintaining the dependencies across multi-module projects has become a challenge over time. Let’s see in detail how the evolution of dependencies management across multi-module projects happened and the problems faced. Please check out my previous post on Kotlin DSL for a better understanding
The core part of this post is how we can achieve better dependencies management using buildSrc and Kotlin DSL
Problem
If you want to skip the evolution process move to the usage of buidSrc
with Kotlin DSL section else continue reading.
Let’s take a multi-module app to understand the problem. Manually declaring versions along with dependencies across multi modules is our first approach. That would look something like below
At first module build.gradle file we declare dependencies
implementation "androidx.appcompat:appcompat:1.0.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41"
xxxxxx
In the second module build.gradle fiile we declare same dependencies
implementation "androidx.appcompat:appcompat:1.0.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41"
xxxxxxxx
As we are defining dependency versions at each build.gradle file this has created problems like conflicting versions if not upgraded correctly. It’s very hard to manage the version upgrades of dependencies and config data. Whenever there is a change in dependency if we have more modules there was a lot of manual process of going to each and every module and checking whether the dependency is exiting or not if found updating and then moving to next.
Configure project-wide properties
Then we moved to set project-wide properties using Gradle Extra properties. For this approach, we used to define the config data and dependency versions at the project or…