Gradle,“源兼容性"与“目标兼容性"? [英] Gradle, "sourceCompatibility" vs "targetCompatibility"?
问题描述
sourceCompatibility
和 targetCompatibility
之间的关系/区别是什么?当它们设置为不同的值时会发生什么?
What is the relationship/difference between sourceCompatibility
and targetCompatibility
? What happens when they are set to different values?
根据 Gradle 文档:
sourceCompatibility
是编译 Java 源代码时使用的 Java 版本兼容性."targetCompatibility
是要为其生成类的 Java 版本."
sourceCompatibility
is "Java version compatibility to use when compiling Java source."
targetCompatibility
is "Java version to generate classes for."
我的理解是 targetCompatibility
会生成与特定 Java 版本兼容的 Java 字节码,这是 sourceCompatibility
功能的子集吗?
My understanding is that targetCompatibility
will generate java bytecode that is compatible with a specific version of Java, is this a subset of the functionality of sourceCompatibility
?
推荐答案
targetCompatibility
和 sourceCompatibility
映射到 -target release
和 -javac 中的源发布
.Source 基本上是源语言级别,target 是生成的字节码级别.
targetCompatibility
and sourceCompatibility
maps to -target release
and -source release
in javac. Source is basically the source language level and target is the level of the bytecode that is generated.
更多详细信息可以在 javac 交叉编译部分.
More details can be found in the javac the cross compilation section.
这篇关于Gradle,“源兼容性"与“目标兼容性"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!