Gradle 将 groovy 翻译成插件的 kotlin
Gradle translate groovy to kotlin for plugins
我目前有一个可以正常工作的 init.gradle 文件:
initscript {
repositories {
jcenter()
}
dependencies {
classpath("com.github.ben-manes:gradle-versions-plugin:+")
}
}
allprojects {
apply plugin: com.github.benmanes.gradle.versions.VersionsPlugin
}
现在我想转向 kotlin DSL,因为我正在从事的所有其他项目都已转移。
所以我创建了这个:
initscript {
repositories {
jcenter()
}
dependencies {
classpath("com.github.ben-manes:gradle-versions-plugin:+")
}
}
allprojects {
apply(plugin = com.github.benmanes.gradle.versions.VersionsPlugin)
}
不幸的是,我收到以下错误:
Script compilation error:
Line 11: apply(plugin = com.github.benmanes.gradle.versions.VersionsPlugin)
^ Classifier 'VersionsPlugin' does not have a companion object, and thus must be initialized here
当我尝试将 "
放在插件周围时,出现错误:
* What went wrong:
Plugin with id 'com.github.benmanes.gradle.versions.VersionsPlugin' not found.
当我尝试时
apply<VersionsPlugin>()
我得到:
Line 10: apply<VersionsPlugin>()
^ Unresolved reference: VersionsPlugin
当我尝试时:
apply(plugin = "com.github.ben-manes.versions")
我得到:
* What went wrong:
Plugin with id 'com.github.ben-manes.versions' not found.
在 gradle documentation 中,我刚刚找到有关如何初始化新插件的提示,而不是如何添加现有插件的提示。
这里有人可以帮助我吗?
有专门的 Kotlin 扩展函数
apply<VersionsPlugin>()
// or
apply(plugin = "com.github.ben-manes.versions")
更新:
第一个选项对我来说效果很好。 init.gradle.kts
文件的完整内容:
import com.github.benmanes.gradle.versions.VersionsPlugin
initscript {
repositories {
jcenter()
}
dependencies {
classpath("com.github.ben-manes:gradle-versions-plugin:+")
}
}
allprojects {
apply<VersionsPlugin>()
}
用法:./gradlew dependencyUpdates -I init.gradle.kts
第二个选项确实失败了,抱歉。原因我不清楚。
我目前有一个可以正常工作的 init.gradle 文件:
initscript {
repositories {
jcenter()
}
dependencies {
classpath("com.github.ben-manes:gradle-versions-plugin:+")
}
}
allprojects {
apply plugin: com.github.benmanes.gradle.versions.VersionsPlugin
}
现在我想转向 kotlin DSL,因为我正在从事的所有其他项目都已转移。
所以我创建了这个:
initscript {
repositories {
jcenter()
}
dependencies {
classpath("com.github.ben-manes:gradle-versions-plugin:+")
}
}
allprojects {
apply(plugin = com.github.benmanes.gradle.versions.VersionsPlugin)
}
不幸的是,我收到以下错误:
Script compilation error:
Line 11: apply(plugin = com.github.benmanes.gradle.versions.VersionsPlugin)
^ Classifier 'VersionsPlugin' does not have a companion object, and thus must be initialized here
当我尝试将 "
放在插件周围时,出现错误:
* What went wrong:
Plugin with id 'com.github.benmanes.gradle.versions.VersionsPlugin' not found.
当我尝试时
apply<VersionsPlugin>()
我得到:
Line 10: apply<VersionsPlugin>()
^ Unresolved reference: VersionsPlugin
当我尝试时:
apply(plugin = "com.github.ben-manes.versions")
我得到:
* What went wrong:
Plugin with id 'com.github.ben-manes.versions' not found.
在 gradle documentation 中,我刚刚找到有关如何初始化新插件的提示,而不是如何添加现有插件的提示。
这里有人可以帮助我吗?
有专门的 Kotlin 扩展函数
apply<VersionsPlugin>()
// or
apply(plugin = "com.github.ben-manes.versions")
更新:
第一个选项对我来说效果很好。 init.gradle.kts
文件的完整内容:
import com.github.benmanes.gradle.versions.VersionsPlugin
initscript {
repositories {
jcenter()
}
dependencies {
classpath("com.github.ben-manes:gradle-versions-plugin:+")
}
}
allprojects {
apply<VersionsPlugin>()
}
用法:./gradlew dependencyUpdates -I init.gradle.kts
第二个选项确实失败了,抱歉。原因我不清楚。