Using Kotlin to maintain our Gradle dependencies within the buildSrc directory can be really great.

  1. Allows us to use a familiar syntax
  2. Provides auto-complete within Groovy or Kotlin Gradle scripts
  3. Can click through to a particular dependencies definition

Sweet 🍭

→ /buildSrc/src/main/java/com/myapp/Versions.kt

package com.myapp

object Versions {
  object AndroidX {
    const val appCompat = "1.0.2"
  }
  const val kotlin = "1.3.10"
  ...
}

→ /buildSrc/src/main/java/com/myapp/Libs.kt

package com.myapp

object Libs {
  object AndroidX {
    const val appCompat = "androidx.appcompat:appcompat:${Versions.AndroidX.appCompat}"
  }
  const val kotlinStdlib = "org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}" 
}

→ /src/app/build.gradle

import com.myapp.Libs

dependencies {
  implementation Libs.kotlinStdlib
  implementation Libs.AndroidX.appCompat
}

Thanks for reading and happy coding! 🙏