Migrating build logic from Groovy to Kotlin

Hi,

I need to migrate this code to build.gradle.kts. What result in Kotlin?

Thanks

build.groovy

task annotate(dependsOn:compileScala, type: Exec)  {
    if (logging.level >= LogLevel.INFO) {
        args '-verbose'
    }
    doFirst{
        args '-proc:only'
        args '-d'
        args compileJava.destinationDir
        args '-classpath'
        args compileJava.classpath.getAsPath() + java.io.File.pathSeparatorChar + compileJava.destinationDir
        if (logging.level >= LogLevel.INFO) {
            args '-verbose'
        }
        fileTree(compileScala.destinationDir).each { File file ->
            if(file.path.contains('META-INF')) {
                return
            }
            if(!file.path.endsWith('class')) {
                return
            }
            args file.path.minus(compileScala.destinationDir).minus('.class').substring(1).replaceAll(Matcher.quoteReplacement(File.separator),'.')
        }
    }
    executable "javac"
}
compileScala.doLast {annotate.execute()}