javamavenjava-17backwards-compatibilityjava-21

Compatibility of Jar compiled with newer JDK


I have a maven project using Java 17. The maven-compiler-pugin is set to <release>17</release>.
If I build this project with a newer JDK version (for example 21), will the produced Jar still be runnable with a JRE 17?


Solution

  • Short answer - yes. The release property you're using should cover both the produced class version and the usage of API that is available on Java 17.

    There's always a caveat that you may be implicitly relying on some undocumented internal behavior and/or bug fix present in Java 21 that won't be present in Java 17, but those should really be rare cases.