问题描述
我有使用intellij为kotlin 1.2.10配置的最简单的gradle项目.这是我的build.gradle文件:
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'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
group 'com.ali'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
我有一个简单的java界面:
And I have a simple java interface:
public interface MyMath {
static int myAbs(int input) {
return Math.abs(input);
}
}
当我导入此接口并尝试调用myAbs
方法时,它将失败,并显示以下错误:
When I import this interface and try to call myAbs
method it fails with this error:
Error:(6, 12) Kotlin: Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'
我创建了一个intellij kotlin应用程序,它运行正常.这是新的Kotlin gradle插件中的错误吗?
I have created an intellij kotlin app and it was working correctly. Is it a bug in new Kotlin gradle plugin?
推荐答案
原来,这是我在intellij设置中的kotlin编译器配置.在Settings > Build, Execution, Deployment > Compiler > Kotlin Compiler
中,应将名为Target JVM version
的设置设置为1.8.
It turned out that it was my kotlin compiler configuration in intellij settings. In Settings > Build, Execution, Deployment > Compiler > Kotlin Compiler
a setting called Target JVM version
should have been set to 1.8.
这篇关于为什么Kotlin Gradle插件无法使用1.8 Target构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!