Kotlin的“使用Gradle”教程中描述的这个kotlin("...")方法是什么?他们提到了这个语法。
plugins {
kotlin("jvm") version "1.3.71"
}我看到它也在更多的地方使用,而不仅仅是插件。例如,它可以是用于获取Kotlin依赖项。
dependencies {
implementation(kotlin("stdlib-jdk8"))
}我已经尝试谷歌这个,但我有困难找到结果,因为Gradle也使用一个Kotlin DSL以及两个结果是混合的。
运行gradle init --dsl kotlin --type kotlin-library会输出“普通”语法(请参阅下面的片段输出),我无法在这个奇怪的kotlin("...")部分找到关于它可以和不能用于什么的文档。如果我像上面一样使用kotlin("...")方法,它仍然有效,但是我正在试图找出它是什么以及它从哪里来的。
plugins {
// Apply the Kotlin JVM plugin to add support for Kotlin.
id("org.jetbrains.kotlin.jvm") version "1.3.71"
// Apply the java-library plugin for API and implementation separation.
`java-library`
}
// ...
dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// Use the Kotlin test library.
testImplementation("org.jetbrains.kotlin:kotlin-test")
// Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}发布于 2020-03-24 17:58:37
它是Gradle提供的扩展函数。它在gradle-kotlin-dsl-<version>.jar!/org/gradle/kotlin/dsl/KotlinDependencyExtensions.kt中发布。通过Ctrl+clicking更多地了解IDE中的函数名。
/**
* Builds the dependency notation for the named Kotlin [module] at the given [version].
*
* @param module simple name of the Kotlin module, for example "reflect".
* @param version optional desired version, unspecified if null.
*/
fun DependencyHandler.kotlin(module: String, version: String? = null): Any =
"org.jetbrains.kotlin:kotlin-$module${version?.let { ":$version" } ?: ""}"https://stackoverflow.com/questions/60836231
复制相似问题