3

Can javac 11 compile binaries/jars that will run on a java 8 JVM?

If so, with what flags?

Will setting gradle source compatibility to 11 and target compatibility to 8 work?

tpdi
  • 34,554
  • 11
  • 80
  • 120

1 Answers1

5

Yes, but not with source=11 and target=8; only source=8 target=8 will work. You can't use any java features introduced in java9, 10, or 11.

On the command line, the javac option you're looking for is -release 8 (which is like -source 8 -target 8 but shorter and better).

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
  • 3
    [`--release 8` is not _just_ shorthand for `-source 8 -target 8`](https://stackoverflow.com/questions/43102787/what-is-the-release-flag-in-the-java-9-compiler). – Slaw Feb 25 '19 at 23:39
  • "(which is *like* `-source 8 -target 8` but shorter, **and better**)" – Andreas Feb 26 '19 at 00:02