Migrate nested extra properties from .gradle to .gradle.kts (DSL)

Viewed 164

Creating example:

ext {
    versions = [
            kotlin     : "1.3.72",

            application: [
                    versionName     : getVersionName(),
                    versionCode     : getVersionCode(),
                    imageVersionCode: getImageVersionCode(),
            ],
            android    : [
                    compileSdk: 29,
                    minSdk    : 21,
                    targetSdk : 29,
                    java      : JavaVersion.VERSION_1_8,
            ],
    ]
}

Using example

android {
    compileSdkVersion versions.android.compileSdk
    defaultConfig {
        minSdkVersion versions.android.minSdk
        targetSdkVersion versions.android.targetSdk
        ...
    }
    ...
}

I found examples without nesting for .kts:

val springVersion by extra("3.1.0.RELEASE")
val emailNotification by extra { "build@master.org" }

But I can't find any documentation to write this code on Kotlin DSL.

1 Answers

here

val versions by extra( mapOf(
    "kotlin" to "1.3.72",
    "application" to mapOf(
        "versionName" to project.version,
        "versionCode" to project.version,
        "imageVersionCode" to project.version
    ),
    "android" to mapOf(
        "compileSdk" to 29,
        "minSdk" to 21,
        "targetSdk" to 29,
        "java" to JavaVersion.VERSION_1_8
    )
))
Related