[英]Move to OpenJDK-11 but compile in Java 8
I have an existing Spring boot
App that i build through gradle
. 我有一个现有的
Spring boot
应用程序,我通过gradle
构建。 All these days I have been using JDK / JRE 8
and now I am trying to use JDK-11
所有这些天我一直在使用
JDK / JRE 8
,现在我正在尝试使用JDK-11
So to check the Compatability, I am setting the JAVA_HOME
to JDK-11
but trying to compile in Java 8
mode 因此,为了检查Compatability,我将
JAVA_HOME
为JDK-11
但尝试在Java 8
模式下进行编译
I added the below block in my build.gradle
我在
build.gradle
添加了以下块
compileJava {
targetCompatibility = '1.8'
}
and then I set JAVA_HOME
explicitly set JAVA_HOME=C:\\Users\\arun\\Desktop\\jdk-11.0.1
然后我设置
JAVA_HOME
显式set JAVA_HOME=C:\\Users\\arun\\Desktop\\jdk-11.0.1
and then execute gradlew clean build
然后执行
gradlew clean build
But I am stopped with the below exception 但是我因以下例外而停止了
> 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
How to point my JAVA_HOME
to JDK-11
but still execute it in Java-8
mode ? 如何将我的
JAVA_HOME
指向JDK-11
但仍然以Java-8
模式执行它?
I'd say : 我会说 :
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
Because the default value of sourceCompatibility is the version of the current JVM in use. 因为sourceCompatibility的默认值是当前使用的JVM的版本。
source : https://docs.gradle.org/current/userguide/java_plugin.html 来源: https : //docs.gradle.org/current/userguide/java_plugin.html
you need to set the sourceCompatibility too. 你也需要设置sourceCompatibility。
See this post here Gradle, "sourceCompatibility" vs "targetCompatibility"? 在这里看到这篇文章Gradle,“sourceCompatibility”vs“targetCompatibility”?
As of Java 9 you can use the --release N option to cross-compile with Gradle. 从Java 9开始,您可以使用--release N选项与Gradle交叉编译。 Setting the sourceCompatibility and targetCompatibility is not enough because in that case you need to set the bootClasspath to JDK N too.
设置sourceCompatibility和targetCompatibility是不够的,因为在这种情况下,您还需要将bootClasspath设置为JDK N. See What is the --release flag in the Java 9 compiler?
请参阅Java 9编译器中的什么是--release标志? for more details.
更多细节。
Instead, use the Java 9+ "--release" compilerArg like this: 相反,使用Java 9+“--release”compilerArg如下:
compilerArgs.addAll(['--release', '8']) compilerArgs.addAll([' - release','8'])
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.