Compile Jasper Reports w/Kotlin During Build?

My question is very similar to the following post in the old forum, but I use kotlin for my gradle build instead of groovy. I think I have most of the groovy solution converted, except I keep having problems with the “jrc” ant task params:

How to compile JasperReports (.jrxml) files during build process?

Figured it out myself. Below is what I ended up going with:

val jasperreports by configurations.creating

dependencies {

val compileJasperReports = tasks.register("compileJasperReports") {
    description = "Compiles source jasper reports files."
    doLast  {
        println("running compileJasperReports task")
        val jasperSourceDir = file(relativePath("src/main/resources/reports"))
        val jasperTargetDir = file("build/classes/java/main/reports")
        println("jasperSourceDir = " + jasperSourceDir)
        println("jasperTargetDir = " + jasperTargetDir)
        ant.withGroovyBuilder {
            "taskdef"("name" to "jrc", "classname" to "net.sf.jasperreports.ant.JRAntCompileTask", "classpath" to jasperreports.asPath)
            "jrc"("srcdir" to jasperSourceDir, "destdir" to jasperTargetDir, "includes" to "**/*.jrxml")

tasks.classes {