Search code examples
kotlingradlegradle-kotlin-dsl

How to define a variable for all Gradle subprojects using Gradle Kotlin DSL


I am following this guide.

The guide reads: Extra properties on a project are visible from its subprojects. This does not seem to work for me, as the following does not work:

In build.gradle.kts I have:

val ktorVersion by extra("1.3.2")

In subproject/build.gradle.kts I have:

dependencies {
    implementation("io.ktor:ktor-server-core:$ktorVersion")
}

Solution

  • In the project level build.gradle.kts:

    val ktorVersion by extra { "1.3.2" }
    

    In the subproject/build.gradle.kts:

    val ktorVersion: String by rootProject.extra
    
    dependencies {  
       implementation("io.ktor:ktor-server-core:$ktorVersion")
    }
    

    For more info: Gradle docs on Extra properties