我正在尝试像在 groovy 中那样组织我的构建文件,方法是将值放在一个单独的文件中以供重用。但我无法理解在 kotlin DSL 中做同样事情的语法。
这是我在 root build.gradle.kts 中使用的内容:
applyFrom("config.gradle.kts")
buildscript {
repositories {
google()
jcenter()
}
dependencies {
val test = project.extra["minSdkVer"]
classpath("com.android.tools.build:gradle:3.0.0-alpha4")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-5")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
这是正在引用的 config.gradle.kts 中的内容:
mapOf(
Pair("minSdkVer", 22),
Pair("targetSdkVer", 25),
Pair("compiledSdkVer", 25),
Pair("buildToolsVer", "26-rc4")
).entries.forEach {
project.extra.set(it.key, it.value)
}
但是有一个错误:
无法在额外属性扩展上获取属性“minSdkVer”,因为它不存在