在Kotlin項目中,什麼是合適的Gradle腳本以確保我的類將被編譯爲字節代碼ver 52(Java 8)?如何在Gradle項目中將Kotlin的字節碼版本設置爲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" } }
看起來你可能需要在compileTestKotlin塊複製這此配置也適用於測試代碼。如果我對此有錯,我想知道它和爲什麼。 – Mark