How to set up Kotlin's byte code version in Gradle project to Java 8?

As Mark pointed out on Debop's answer, you have to configure both compileKotlin and compileTestKotlin. You can do it without duplication this way:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
  kotlinOptions {
    jvmTarget = "1.8"
  }
}

For a pure Kotlin project, I don't think the options sourceCompatibility and targetCompatibility do anything, so you may be able to remove them.

Ref: https://kotlinlang.org/docs/reference/using-gradle.html#compiler-options


In case someone uses gradle with kotlin-dsl instead of groovy:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

// compile bytecode to java 8 (default is java 6)
tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}

Kotlin 1.1 in Gradle. in console you have error about inline (your installed compiler is 1.0.x) If run gradle task in IntelliJ IDEA, your code compiled by kotlin 1.1 compiler

compileKotlin {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

    kotlinOptions {
        jvmTarget = "1.8"
        apiVersion = "1.1"
        languageVersion = "1.1"
    }
}

Tags:

Gradle

Kotlin