将嵌套的额外属性从 .gradle 迁移到 .gradle.kts (DSL)

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

创建示例:

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,
            ],
    ]
}

使用示例

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

I found 没有 .kts 嵌套的例子:

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

但是我找不到任何文档来在 Kotlin DSL 上编写这段代码。

这里

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
    )
))