How are gradle extra properties set in the Kotlin DSL?

 ̄綄美尐妖づ 提交于 2019-12-04 01:48:00

A correct fix: Gradle collects and applies the buildscript { ... } blocks from your script strictly before executing anything else from it. So, to make your properties from config.gradle.kts available inside the buildscript, you should move applyFrom("config.gradle.kts") to your buildscript { ... } block:

buildscript {
    applyFrom("config.gradle.kts")

    /* ... */
}

Another possible mistake is using an extra property as extra["minSdkVer"] in a scope of another ExtensionAware, like a task in this example:

val myTask = task("printMinSdkVer") {
    doLast {
        println("Extra property value: ${extra["minSdkVer"]}")
    }
}

In this case, extra.get(...) uses not the project.extra but the extra of the task.

To fix that, specify that you work with the project. Direct usage:

println(project.extra["minSdkVer"])

And for delegation.

val minSdkVer by project.extra
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!