[英]How to Run a Kotlin Task from Android Project's build.gradle?
My project's build.gradle is in Groovy but I'd like to run as a gradle task the main function of a Kotlin class in a root directory kt file.我的项目的 build.gradle 在 Groovy 中,但我想作为 gradle 任务运行根目录 kt 文件中 Kotlin 类的主要功能。
I don't know where to begin in terms of syntax.我不知道从语法方面从哪里开始。
something like this?像这样的东西? I came up with this after searching around a bit.
经过一番搜索,我想出了这个。
task doKotlinTask(type: JavaExec) {
classpath "/"
main = "KotlinTaskKt"
}
Create in the root directory buildSrc/src/main/kotlin
and place MyKotlinClass.Kt
there.在根目录中创建
buildSrc/src/main/kotlin
并将MyKotlinClass.Kt
那里。 Create buildSrc/build.gradle
to add any dependencies for MyKotlinClass.创建
buildSrc/build.gradle
为 MyKotlinClass 添加任何依赖项。
Then in your project or app's build.gradle, append the following:然后在您的项目或应用程序的 build.gradle 中,附加以下内容:
import my.package.for.the.kotlin.class
task doKotlinTask(type: MyKotlinClass) {
someParamForTheTask = "hello world"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.