Stephan Schroeder
04/29/2019, 11:16 AMval kotlinVersion = "1.3.21"
plugins {
kotlin("jvm") version kotlinVersion
...
}
dependencies {
...
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")
}
But this fails (“String can’t be called from this context by implicit receiver”) for the usage in plugins.yousefa2
04/29/2019, 11:25 AMproject.extensions
. Creating the version in the extensions and getting them in the dependencies
block.Stephan Schroeder
04/29/2019, 11:53 AMextensions.apply {
add(String.javaClass, "kotlinVersion", "1.3.21")
}
plugins {
kotlin("jvm") version project.extensions["kotlinVersion"] as String
...
}
dependencies {
...
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:${extensions["kotlinVersion"]}")
}
works for the dependency- but not for the plugins-block. It’s the same problem as before (“can’t be called in this context by implicit receiver”) this time it’s the project variable that is flagged in this way.gildor
04/29/2019, 1:16 PMproperties
object instead using this ugly extensions blockStephan Schroeder
04/29/2019, 3:52 PMdependencies {
val jacksonVersion = "2.9.8"
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jacksonVersion")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
}
or I put it into the properties (which i have to awkwardly cast because Kotlin interpretes MutableMap<String, ?> as MutableMap<String, Nothing>)
(properties as MutableMap<String, Any>).apply {
put("jacksonVersion", "2.9.8")
}
dependencies { implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${properties[jacksonVersion]}")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${properties[jacksonVersion]}")
}
?!gildor
04/29/2019, 5:12 PMval jacksonVersion by project
efemoney
05/01/2019, 4:04 AMorg.gradle.kotlin.dsl
😉gildor
05/02/2019, 1:34 AM