简体   繁体   中英

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.

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. Create buildSrc/build.gradle to add any dependencies for MyKotlinClass.

Then in your project or app's build.gradle, append the following:

import my.package.for.the.kotlin.class
task doKotlinTask(type: MyKotlinClass) {
  someParamForTheTask = "hello world"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM