Repository: JetBrains/kotlin
File: ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt (Kotlin)

Code before:
            moduleName = defaultModuleName
        }

        moduleName?.let {
            args.add("-module-name")
            args.add(moduleName!!)
        }

        if (noStdlib) args.add("-no-stdlib")
        if (noReflect) args.add("-no-reflect")
        if (includeRuntime) args.add("-include-runtime")
    }

    override fun execute() {
        if (!fork)
            super.execute()
        else {
            exec()
        }
    }

    private fun exec() {
        val javaHome = System.getProperty("java.home")
        val javaBin = javaHome + separator + "bin" + separator + "java"
        val classpath = System.getProperty("java.class.path")
        var redirector = Redirector(this)

        fillArguments()

        val command = ArrayList<String>()
        command.add(javaBin)
        command.addAll(cmdl.vmCommand.arguments) // jvm args
        command.add("-cp")
        command.add(classpath + pathSeparator + KotlinAntTaskUtil.compilerJar.canonicalPath)
        command.add(compilerFqName)
        command.addAll(args) // compiler args

        // streamHandler: used to handle the input and output streams of the subprocess.
        // watchdog: a watchdog for the subprocess or <code>null</code> to disable a timeout for the subprocess.
        // TODO: support timeout for the subprocess
        val exe = Execute(redirector.createHandler(), null)
        exe.setAntRun(getProject())
        exe.commandline = command.toTypedArray()
        log("Executing command: ${command.joinToString(" ")}", LogLevel.DEBUG.level)
        log("Compiling ${src!!.list().toList()} => [${output!!.canonicalPath}]")
        var exitCode = exe.execute()
        redirector.complete()
        if (failOnError && exitCode != 0) {
            throw BuildException("Compile failed; see the compiler error output for details.")
        }
    }

Review comment (suggestion):
Please fix the warning here and on `exitCode` below ("Variable is never modified and can be declared immutable using 'val'")

Code after:
            moduleName = defaultModuleName
        }

        moduleName?.let {
            args.add("-module-name")
            args.add(moduleName!!)
        }

        if (noStdlib) args.add("-no-stdlib")
        if (noReflect) args.add("-no-reflect")
        if (includeRuntime) args.add("-include-runtime")
    }

    override fun execute() {
        if (!fork)
            super.execute()
        else {
            exec()
        }
    }

    private fun exec() {
        val javaHome = System.getProperty("java.home")
        val javaBin = javaHome + separator + "bin" + separator + "java"
        val redirector = Redirector(this)

        fillArguments()

        val command = ArrayList<String>()
        command.add(javaBin)
        command.addAll(cmdl.vmCommand.arguments) // jvm args
        command.add("-Dorg.jetbrains.kotlin.cliMessageRenderer=FullPath") // same MessageRenderer as non-forking mode
        command.add("-cp")
        command.add(KotlinAntTaskUtil.compilerJar.canonicalPath)
        command.add(compilerFqName)
        command.addAll(args) // compiler args

        // streamHandler: used to handle the input and output streams of the subprocess.
        // watchdog: a watchdog for the subprocess or <code>null</code> to disable a timeout for the subprocess.
        // TODO: support timeout for the subprocess
        val exe = Execute(redirector.createHandler(), null)
        exe.setAntRun(getProject())
        exe.commandline = command.toTypedArray()
        log("Executing command: ${command.joinToString(" ")}", LogLevel.DEBUG.level)
        log("Compiling ${src!!.list().toList()} => [${output!!.canonicalPath}]")
        val exitCode = exe.execute()
        redirector.complete()
        if (failOnError && exitCode != 0) {
            throw BuildException("Compile failed; see the compiler error output for details.")
        }
    }