Intellij refuses to set the Kotlin target jvm to 1.8?
1 2 3 | 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 -> ^ |
好吧...我不是要为1.6编译。
我的gradle构建文件...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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" } |
我没有地方要检查
是的,我尝试过使缓存无效并重新启动Intellij。它无法解决此问题。
为Java 1.8添加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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" } |
与
1 2 3 4 5 6 7 8 9 | tasks { withType<KotlinCompile> { kotlinOptions.jvmTarget ="1.8" } } // I am using latest dsl and gradle val kotlinVersion ="1.3.30" val gradleVersion ="5.4+" |
由于为所有相关配置生成了编译任务,因此仅更改
尝试使用任务筛选来配置所有
1 2 3 | tasks.withType(KotlinCompile) { kotlinOptions.jvmTarget ="1.8" } |