Class JdkSourceLevelSupport
java.lang.Object
org.apache.maven.impl.JdkSourceLevelSupport
Utility class for JDK source level compatibility checks.
Maps JDK major versions to their supported --source/--release levels,
based on the javac retirement schedule defined in
JEP 182 and subsequent JDK releases.
The retirement schedule follows these milestones:
- JDK 9: removed
--source 1through5, minimum is6 - JDK 12: removed
--source 6, minimum is7 - JDK 21: removed
--source 7, minimum is8
-
Method Summary
Modifier and TypeMethodDescriptionstatic intReturns the major version of the currently running JDK.static intlatestJdkForSourceLevel(int sourceLevel) Returns the latest JDK major version that still supports the given--sourcelevel.static intminimumSupportedSourceLevel(int jdkMajor) Returns the minimum--sourcelevel supported by a given JDK major version.static intnormalizeSourceLevel(String version) Normalizes a source level string to a major version number.static booleansupportsSourceLevel(int jdkMajor, int sourceLevel) Returns whether a given JDK version supports the specified--sourcelevel.
-
Method Details
-
minimumSupportedSourceLevel
public static int minimumSupportedSourceLevel(int jdkMajor) Returns the minimum--sourcelevel supported by a given JDK major version.- Parameters:
jdkMajor- the JDK major version (e.g.,17,21)- Returns:
- the minimum supported source level
-
supportsSourceLevel
public static boolean supportsSourceLevel(int jdkMajor, int sourceLevel) Returns whether a given JDK version supports the specified--sourcelevel.- Parameters:
jdkMajor- the JDK major versionsourceLevel- the desired source level- Returns:
trueif the JDK supports the source level
-
normalizeSourceLevel
Normalizes a source level string to a major version number.Handles legacy formats:
"1.5"→5"1.8"→8"11"→11"21.0.1"→21
- Parameters:
version- the source level string- Returns:
- the normalized major version, or
-1if the string cannot be parsed
-
latestJdkForSourceLevel
public static int latestJdkForSourceLevel(int sourceLevel) Returns the latest JDK major version that still supports the given--sourcelevel.Based on the retirement schedule:
- source 1–5 → last supported by JDK 8
- source 6 → last supported by JDK 11
- source 7 → last supported by JDK 20
- source 8+ → still supported by current JDKs
- Parameters:
sourceLevel- the source level- Returns:
- the latest JDK major version that supports it, or
-1if the source level is still supported by all current JDKs
-
getRunningJdkMajor
public static int getRunningJdkMajor()Returns the major version of the currently running JDK.- Returns:
- the running JDK major version
-