Using Multiple Build JDKs
To be able 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.
This topic explains how IntelliJ IDEA selects a build JDK if multiple JDKs are defined, and how to configure them:
How does IntelliJ IDEA know which JDK to use?
This section explains the algorithm of choosing a build JDK by IntelliJ IDEA if multiple JDKs are configured on the per-module basis. IntelliJ IDEA does the following to determine which JDK to use for compilation:
- IntelliJ IDEA checks all JDKs used in the project (i.e. the JDKs 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, the JDK version used for running IntelliJ IDEA will be used. 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 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.
Configuring build JDK
- Open the Project Structure dialog.
- Do one of the following:
- To set a build JDK for an entire project, select Project in the left pane. On the right, under Project SDK, select the required SDK from the drop-down list.
- To set a build JDK for a specific module, select Modules in the left pane, then select the required module in the central pane and specify a JDK in the Module SDK drop-down list.
If you haven't created any projects before and specified the path to the JDK, click New, select JDK and browse for the JDK installation folder in the dialog that opens.
Note that you can also override the project- or module-level JDK settings for a particular debug or testing session by editing the appropriate Run/Debug Configuration.