I may do some cross-compilations for legacy projects and I noticed with recent JDKs that we are limited to some specific versions for the source
, target
and release
JVM arguments.
How to get the supported versions for these arguments ?
source: The version that your source code requires to compile. target: The oldest JRE version you want to support.
We defined a new command-line option, --release , which automatically configures the compiler to produce class files that will link against an implementation of the given platform version.
Maven Configuration The Maven tool uses JDK version 11.0.
Indeed the supported values depend on the major JDK version used.
You can find the information on the javac
documentation of the respective major JDK versions (the links are referenced below).
Some general notes about these arguments :
The source
and the target
version in the Maven configuration should not be superior to the JDK version used.
A older version of the JDK cannot compile with a more recent version since it doesn't know its specification.
Beware : while a recent JDK can accept as source
compilation an older Java version, it doesn't mean that you can select as source
any supported recent version and as target
any older version that is documented as supported (see below).
In indeed, Java versions may introduce new features that were not designed to be compatible with older Java version at compile time/run time.
For example a JDK 11 can compile classes with 8 as source
compiler version. By choosing also 8 as target
compiler version, compilation will pass.
But if you change your mind and that you want to compile with 11 as source
and 8 as target
, compilation will fail.
That is not always explicitly documented in the javac documentation.
The release
argument exists from Java 9.
As the source
and the target
are the same, the release
argument should be favored over source
and target
. It is shorter to specify and it ensures a better cross compilation compatibility and whatever even if you don't do cross compilations, it will not hurt.
For more explanations please refer to this excellent answer.
source/target/release supported versions :
For Java 7
source
:1.3, 1.4, 1.5 (also 5), 1.6 (also 6), and 1.7 (also 7).
target
:1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6 (also 6), and 1.7 (also 7).
For Java 8
source
:1.3, 1.4, 1.5 (also 5), 1.6 (also 6), 1.7 (also 7), and 1.8 (also 8).
target
:1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6 (also 6), 1.7 (also 7), and 1.8 (also 8).
For Java 9
source
:1.6 (also 6), 1.7 (also 7), 1.8 (also 8), and 9.
target
:1.6 (also 6), 1.7 (also 7), 1.8 (also 8) and 9.
release
:6, 7, 8, and 9.
For Java 10
source
:1.6 (also 6), 1.7 (also 7), 1.8 (also 8), 9, and 10.
target
:1.6 (also 6), 1.7 (also 7), 1.8 (also 8), 9 and 10.
release
:6, 7, 8, 9, and 10.
For Java 11
source/target/release
:6, 7, 8, 9, 10, and 11.
You could have more details in the javac documentation for JDK 1.8, JDK 9, JDK 10 and JDK 11
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With