为什么Kotlin Gradle插件无法使用1.8 Target构建? [英] Why kotlin gradle plugin cannot build with 1.8 target?

查看:383
本文介绍了为什么Kotlin Gradle插件无法使用1.8 Target构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用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构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆