For describing Gradle build scripts, we can use Kotlin via build.gradle.kts
files. It's a common problem to globally define the Kotlin version to be used, both in the dependencies
and also in the build plugin
section (It's rather uncommon to have different versions in use for the given case).
Consider the following code (Gradle 4.3.1):
plugins {
var pluginVersion = "1.2.30"
kotlin("jvm").version(kotlinVersion)
// more
}
var dependencyVersion = "1.2.30"
dependencies {
compile(kotlin("stdlib", kotlinVersion))
compile(kotlin("reflect", kotlinVersion))
testCompile(kotlin("test", kotlinVersion))
// more
}
如您所见,kotlin version
(本例中为1.2.30)的定义为twice:dependencyVersion
和pluginVersion
,通常为does not differ.由于DSL限制,无法从plugins
块外部访问pluginVersion
或从plugins
块内部访问dependencyVersion
.
How can the version string, "1.2.30"
be extracted to a single place?