[英]Move to OpenJDK-11 but compile in Java 8
我有一個現有的Spring boot
應用程序,我通過gradle
構建。 所有這些天我一直在使用JDK / JRE 8
,現在我正在嘗試使用JDK-11
因此,為了檢查Compatability,我將JAVA_HOME
為JDK-11
但嘗試在Java 8
模式下進行編譯
我在build.gradle
添加了以下塊
compileJava {
targetCompatibility = '1.8'
}
然后我設置JAVA_HOME
顯式set JAVA_HOME=C:\\Users\\arun\\Desktop\\jdk-11.0.1
然后執行gradlew clean build
但是我因以下例外而停止了
> Configure project :
Build Version = build-182-ga03cf6c
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> warning: source release 11 requires target release 11
如何將我的JAVA_HOME
指向JDK-11
但仍然以Java-8
模式執行它?
我會說 :
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
因為sourceCompatibility的默認值是當前使用的JVM的版本。
來源: https : //docs.gradle.org/current/userguide/java_plugin.html
你也需要設置sourceCompatibility。
在這里看到這篇文章Gradle,“sourceCompatibility”vs“targetCompatibility”?
從Java 9開始,您可以使用--release N選項與Gradle交叉編譯。 設置sourceCompatibility和targetCompatibility是不夠的,因為在這種情況下,您還需要將bootClasspath設置為JDK N. 請參閱Java 9編譯器中的什么是--release標志? 更多細節。
相反,使用Java 9+“--release”compilerArg如下:
compilerArgs.addAll([' - release','8'])
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.