How to compile against a newer JDK's classpath?
How can I configure IntelliJ IDEA to compile a module against a newer JDK's classpath but emit class files with an older version of bytecode?
Specifically, I want to compile a module against the Java 9 API, but emit Java 1.8 (version 52) class files, so that the code will load in Java 1.8. The optional classes that make use of the Java 9 API will only be used when running on Java 9.
IMHO it should be enough to set the module JDK to a Java 9 JDK, and set the bytecode version of the project to 1.8 in the project settings. However that doesn't work; IntelliJ appears to compile it against the Java 1.8 classpath, even though it should be using the Java 9 JDK, and I get compile errors about missing sumbols anywhere I use the Java 9. I think that is a bug and I have reported it as such.
But is there another way to achieve this?
请先登录再写评论。
Please follow the issue you've reported and another one for updates:
https://youtrack.jetbrains.com/v2/issue/IDEA-184333
https://youtrack.jetbrains.com/v2/issue/IDEA-185700