0

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"
}
Grant Park
  • 1,004
  • 1
  • 9
  • 29

1 Answers1

0

Create in the root directory buildSrc/src/main/kotlin and place MyKotlinClass.Ktthere. 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"
}
Grant Park
  • 1,004
  • 1
  • 9
  • 29