我有一个通过gradle构建的现有Spring boot应用程序。这些天来,我一直在使用JDK / JRE 8,现在我正在尝试使用JDK-11
因此,为了检查兼容性,我将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模式下执行它?
发布于 2019-01-11 21:18:35
我会说:
sourceCompatibility = '1.8'
targetCompatibility = '1.8'因为sourceCompatibility的缺省值是当前使用的JVM的版本。
来源:https://docs.gradle.org/current/userguide/java_plugin.html
发布于 2019-01-11 21:18:31
您还需要设置sourceCompatibility。
请在此处查看此帖子Gradle, "sourceCompatibility" vs "targetCompatibility"?
发布于 2019-07-17 04:58:49
从Java9开始,您可以使用--release N选项与Gradle进行交叉编译。设置sourceCompatibility和targetCompatibility是不够的,因为在这种情况下,还需要将bootClasspath设置为JDK。有关更多详细信息,请参阅What is the --release flag in the Java 9 compiler?。
相反,可以像这样使用Java“-- 9+”compilerArg:
compilerArgs.addAll('--release','8')
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html
https://stackoverflow.com/questions/54147275
复制相似问题