Skip to content

Add property for setting the --release compiler argument #2510

@ijuma

Description

@ijuma

Instead of asking users to install and use the oldest Java version supported by the project, Java 9 can be used thanks to JEP 247. Summary:

A new command-line option, --release, is defined, which automatically configures the compiler to produce class files that will link against an implementation of the given platform version. --release N is roughly equivalent to:

for N < 9: -source N -target N -bootclasspath [documented-APIs-from-N],
for N >= 9: -source N -target N --system [documented-APIs-from-N].

http://openjdk.java.net/jeps/247

Expected Behavior

Similar to how one can currently set sourceCompatibility = 1.7, one should be able to set releaseCompatibility = 7 (or 1.7 maybe). If Java 9 is being used, then --release 7 (1.7 is not supported) would be passed to javac during compilation.

For older Java versions or tools that don't support --release, it probably makes sense to fallback to "--source 1.7 --target 1.7" and print a warning.

Note that IntelliJ already supports this:

"language level is automatically interpreted as -release option when compiling sources with javac 9 or newer"
https://youtrack.jetbrains.com/issue/IDEA-148501

And so does Maven:

https://issues.apache.org/jira/browse/MCOMPILER-270

Current Behavior

This feature is not currently supported. The easiest option at the moment is to use an older JDK. An alternative is to use -source -target and -bootclasspath, but then we need a mechanism to find the older JDK as well and write the code to set the bootclasspath. In some cases people use -source -target with a newer JDK and hope it will be OK (causing subtle issues at times).

Context

Apache Kafka still supports Java 7, so developers have to install this version even though it's no longer available from the Oracle website without a login.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions