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

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

问题描述

我在 kotlin 1.2.10 中使用 Intellij 配置了最简单的 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编译器配置.在<代码>设置>构建、执行、部署 >编译器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.

这篇关于为什么无法使用 1.8 目标构建 kotlin gradle 插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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