使用 Java 9 JDK 定位 Java 6 给出警告

Targeting Java 6 with Java 9 JDK gives warnings

我正在尝试使用 JDK 9 构建项目,因为对 javac 使用 --release 参数意味着它可以为旧版本构建而无需安装相应的 JDK/JRE。我需要支持 Java 6,所以我预先存在的设置需要 Java 6 作为 bootstrapClasspath,另外需要 JDK 8 或 9 作为 gradle 和 IDE。我想删除 JDK 6 以仅使用 9,并稍微整理一下构建。

我的新 build.gradle 具有以下配置:

tasks.withType(JavaCompile) {
    options.compilerArgs.addAll(['--release', '6', "-Xlint"])
}

未设置 sourceCompatibilitytargetCompatibilitybootstrapClasspath 选项,据我所知,--release 参数现在可以处理此问题。

我收到以下警告:

warning: [options] source value 1.6 is obsolete and will be removed in a future release
warning: [options] target value 1.6 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

我知道这些可以被抑制(它就在那里说),但我没想到会看到它们。 使用 --release [7-9] 构建时,这些警告不存在。

对于上下文,这是旧的(现在未使用)“2x JDK”配置:

sourceCompatibility = "1.6"
targetCompatibility = "1.6"

tasks.withType(JavaCompile) {
    options.bootstrapClasspath = new SimpleFileCollection(Arrays.asList(new File("$JDK6_HOME/jre/lib/rt.jar")))
}

我是否错误地设置了编译器参数?有没有办法不设置/取消设置 sourcetarget

虽然这不是来自官方来源,但警告似乎与 "one plus three back" 条款中所述的一致 JEP182#Policy for Retiring javac -source and -target Options

JDK 9 will implement a "one plus three back" support policy meaning that 1.9/9, 1.8/8, 1.7/7, and 1.6/6 will be recognized in that release. That policy will continue in JDK 10.

因此,理想情况下,应该删除 1.6,并在图片中删除 JDK10,并在警告中发挥良好作用,让客户了解该政策。

编辑: 然而,正如 所指出的 JDK10会继续支持--release 6this mailiing list.

所述