Skip to main content

Articles, snippets and thoughts about code from Andrew Lord.

Enable Java 8 compatibility for Kotlin sources

Published on · Updated on
1 minute read

Enabling Java 8 compatibility via the compileOptions block only works for Java sources. To do the same for Kotlin you need to use kotlinOptions on any KotlinCompile Gradle tasks. Interesting…

For Kotlin

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

For Java

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

I hope the article was useful. If you have any feedback or questions please feel free to reach out to me on Twitter.

Thanks for reading and happy coding!

Like what you read? Please share the article.

Avatar of Andrew Lord

Hi, I hope you enjoyed the article. I am Andrew - a builder of apps and developer tools. Articles on the blog focus on all aspects of Android and iOS development using Kotlin and Swift.

Subscribe via RSS