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

时间:2020-08-05 00:29:35

标签: gradle gradle-kotlin-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
        ...
    }
    ...
}

found个示例,没有嵌套.kts:

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

但是我找不到任何文档可以在Kotlin DSL上编写此代码。

1 个答案:

答案 0 :(得分:0)

这里

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