Using Multiple Build JDKs
To compile an application, you need to specify a build JDK. A build JDK can be configured on a project level. If you have a complex project, you may want to configure different JDKs for different modules.
How does IntelliJ IDEA know which JDK to use?
IntelliJ IDEA does the following to determine which JDK to use for compilation if you use different JDKs for modules in your project.
IntelliJ IDEA checks all JDKs that are used in the project: the JDKs that are defined on both the project and module levels.
IntelliJ IDEA calculates the latest of these JDKs. This is necessary to make sure that all modules can be compiled.
If the version of the latest JDK configured is lower than 1.6, IntelliJ IDEA will pick the JDK version that is used for running the IDE. This limitation is related to the fact that the compiler API used by IntelliJ IDEA for building projects is supported starting from JDK 1.6.
Although a specific version of the compiler will be used (in accordance with the selected JDK version), each separate module will be compiled using the javac's cross-compilation feature against the libraries of the JDK defined for this particular module in the project settings.
This protects you from a situation when a module is compiled against newer libraries than those for which dependencies are set.
For instructions on how to set a JDK for a project or a module, refer to Define an SDK.