Why kotlin gradle plugin cannot build with 1.8 target?

前端 未结 10 2070
悲哀的现实
悲哀的现实 2020-12-08 12:50

I have the simplest gradle project configured using intellij for kotlin 1.2.10. Here is my build.gradle file:

buildscript {
    ext.kotlin_version = \'1.2.10         


        
相关标签:
10条回答
  • 2020-12-08 13:20

    Not quite sure why this works, but you could try changing the setting in the Idea itself. Since Gradle from the command line works, but not when building from IntelliJ this is probably the root.

    Go to File -> Project Structure. Go to the Project tab and make sure Project SDK is 8 (or newer) and set the Project language level to Java 8

    The config in there seems to override Gradle for some reason, so changing it should work

    0 讨论(0)
  • 2020-12-08 13:21

    //Just add the below code in your Build gradle(Module:app)

    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        kotlinOptions {
            jvmTarget = "1.8"
        }
     }
    
    0 讨论(0)
  • 2020-12-08 13:21

    This is also set in project settings, under Project Settings > Modules > Kotlin. This was my specific problem... literally the last thing I tried.

    0 讨论(0)
  • 2020-12-08 13:25

    There is a gradle property used by Kotlin plugin which can be used. When you add

    kotlin.setJvmTargetFromAndroidCompileOptions = true
    

    to your gradle.properties file. When you have this configuration on your build.config

    android{
      compileOptions {
          sourceCompatibility = 1.8
          targetCompatibility = 1.8
      }
    }
    

    problem sould be solved.

    0 讨论(0)
提交回复
热议问题