Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij refuses to set the Kotlin target jvm to 1.8?

ParallelStreams.kts:41:15: error: calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'
IntStream.range(0,10).parallel().forEach{a ->
         ^

Ok ... I'm not trying to compile for 1.6.

File > Project Structure > Project has project sdk 1.8 and language level 8.

File > Project Structure > Modules > Kotlin has target platform: JVM 1.8.

File > Project Structure > Facets > Kotlin has target platform: JVM 1.8.

File > Settings > Compiler > Kotlin Compiler has target jvm version 1.8.

My gradle build file ...

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.0'
}

group 'foo'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    //kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation "org.jetbrains.kotlin:kotlin-script-runtime:1.3.0"

    //networking
    implementation 'com.mashape.unirest:unirest-java:1.4.9'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

I'm running out of places to check for 1.8.

And yes, I have tried invalidating the cache and restarting Intellij. It does nothing to resolve this issue.

like image 576
User1291 Avatar asked Feb 11 '19 21:02

User1291


People also ask

How do I change the Kotlin compiler version in Intellij?

Go to Intellij Preferences -> Build, Execution, Deployment -> Kotlin Compiler. Update Language version and Api version to the one you wish. This should be the accepted answer.

What is the latest version of Kotlin?

Kotlin 1.6 was released in November 2021. Kotlin 1.7 was released in June 2022, including the alpha version of the new Kotlin K2 compiler.


2 Answers

Add sourceCompatibility and targetCompatibility for Java 1.8:

plugins {
  id 'org.jetbrains.kotlin.jvm' version '1.3.0'
}

group 'foo'
version '1.0-SNAPSHOT'

repositories {
  mavenCentral()
}

// Add compatibility
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8


dependencies {
  //kotlin
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
  implementation "org.jetbrains.kotlin:kotlin-script-runtime:1.3.0"

  //networking
  implementation 'com.mashape.unirest:unirest-java:1.4.9'
}

compileKotlin {
  kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
  kotlinOptions.jvmTarget = "1.8"
}
like image 75
punchman Avatar answered Oct 17 '22 14:10

punchman


With .kts just use this:

tasks {
    withType<KotlinCompile> {
        kotlinOptions.jvmTarget = "1.8"
    }
}

// I am using latest dsl and gradle 
val kotlinVersion = "1.3.30"
val gradleVersion = "5.4+"
like image 33
Golvanig Avatar answered Oct 17 '22 13:10

Golvanig