相关疑难解决方法(0)

如何在Gradle项目中将Kotlin的字节码版本设置为Java 8?

在Kotlin项目中,什么是正确的Gradle脚本以确保我的类将被编译为字节码52(Java 8)?

出于某种原因,即使我设置了源和目标兼容性,我的类也编译为ver 50(Java 6).至少这是Idea build/classes/...在构建项目后从目录中打开文件时向我显示的内容.

我目前的设置看起来像这样.

buildscript {
    ext {
        kotlinVersion = '1.0.5-2'
        springBootVersion = '1.4.2.RELEASE'
    }
    repositories { mavenCentral() }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
    }
}

apply plugin: 'kotlin'
apply plugin: 'org.springframework.boot'

tasks.withType(JavaCompile) {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

## I also tried this and it hasn't helped
#sourceCompatibility = 1.8
#targetCompatibility = 1.8

repositories { mavenCentral() }

dependencies {
    compile("org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}")
    compile('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
}

dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR2" } }
Run Code Online (Sandbox Code Playgroud)

gradle kotlin

41
推荐指数
7
解决办法
2万
查看次数

标签 统计

gradle ×1

kotlin ×1