12
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.

User1291
  • 7,664
  • 8
  • 51
  • 108
  • I had the same problem that I couldn't find the right setting in IntelliJ IDEA to change the target JVM version for Kotlin scripts using pure IDEA project file structure (not Gradle). It seems that it's 1.6 by default and can't be changed by now. However, If you just want the scripts to run normally, you can bring down all such settings to 6 or 1.6, since the bytecode version doesn't actually affect the program logic or what Kotlin APIs you use. This works for me. – Shreck Ye Sep 28 '19 at 16:50

3 Answers3

6

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"
}
punchman
  • 1,350
  • 1
  • 13
  • 23
4

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+"
Hasta Dhana
  • 4,699
  • 7
  • 17
  • 26
Golvanig
  • 41
  • 2
1

Since compilation tasks are generated for all relevant configurations it is likely that just changing compileKotlin and compileTestKotlin isn't enough.

Try using task filtering to configure all KotlinCompile task instances:

tasks.withType(KotlinCompile) {
    kotlinOptions.jvmTarget = "1.8"
}
Kiskae
  • 24,655
  • 2
  • 77
  • 74