Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Targeting Java 6 with Java 9 JDK gives warnings

I'm trying to build a project using JDK 9, as using the --release argument to javac means it can build for older versions without needing the corresponding JDK/JRE installed. I need to support Java 6 so my preexisting set up requires Java 6 for the bootstrapClasspath and a further JDK 8 or 9 for gradle and the IDE. I'd like to eliminate JDK 6 in favor of just using 9, and tidy the build somewhat.

My new build.gradle has the following configuration:

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

The sourceCompatibility, targetCompatibility and bootstrapClasspath options are not set, as I understand the --release argument handles this now.

I get the following warnings:

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.

I know these can be suppressed (it says it right there), but I wasn't expecting to see them. When building with --release [7-9] these warnings are not present.

For context, this is the old (unused now) '2x JDK' config:

sourceCompatibility = "1.6"
targetCompatibility = "1.6"

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

Am I setting the compiler arguments incorrectly? Is there a way to not set / unset source and target?

like image 609
Sam Avatar asked Dec 14 '17 13:12

Sam


1 Answers

Though this is not from an official source, yet the warning seems to be aligned with the "one plus three back" clause as stated in the 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.

So ideally 1.6 should be removed with JDK10 in picture with the warning taking in good effect for clients to be aware of the policy.

Edit: Yet, as pointed by Alan in comments JDK 10 will continue to support --release 6 as stated in this mailiing list.

like image 152
Naman Avatar answered Nov 02 '22 07:11

Naman