How to centralize dependencies in Gradle Kotlin?

val version = "1.0"
val anotherVersion= "2.0"

val depArray1 = arrayOf("dep1:$version", "dep3:$version", "dep3:$anotherVersion")
val depArray2 = arrayOf("dep4:$anotherVersion", "dep5$version", "dep6:$anotherVersion")

dependencies {
    depArray1.forEach { implementation(it) }
    depArray2.forEach { implementation(it) }
}

implementation doesn’t have vararg params like in groovy dsl, but kotlin dsl still dsl - you just call function one by another and you can run them in the cycle, also you can move your dependecies holder to buildSrc like this:

1 Like