How to reuse dependency versions in subprojects for Kotlin DSL?


I have a multi module Gradle project with Kotlin DSL as build file. Inside of the root build.gradle.kts there is dependencies section for root and subprojects with its own dependencies. I would like to create a variable that can keep version of some dependency and be used in all modules in build.gradle.kts.

Root build.gradle.kts looks like:

buildscript {
// ...
plugins {
// ...
subprojects {
// repositories, plugins, tasks, etc.

dependencies {

Submodule common-module/build.gradle.kts

dependencies {

I would like to declare a variable and assign the version for these dependencies as a value and only reuse it on modules. Some thing like implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-csv:${jacksonVersion}").

How can I do that?


The most modern, type-safe solution of this problem is using version catalogs.

  1. Update Gradle to 7.2.

  2. Add this to your settings.gradle or settings.gradle.kts:


  3. gradle/libs.versions.toml:

    jackson “2.12.5”

    jackson-databind { module “com.fasterxml.jackson:jackson-databind”, version.ref “jackson” }
    jackson-dataformat-csv { module “com.fasterxml.jackson.dataformat:jackson-dataformat-csv”, version.ref “jackson” }

  4. Add dependencies like implementation(libs.jackson.dataformat.csv) in all the subprojects.

Answered By – Commander Tvis

Leave a Comment