You can change the Java compiler version in IntelliJ by configuring the project's SDK. This allows you to use different Java versions for different projects.
Steps:
- Open the Project Structure Dialog: Go to File > Project Structure or press Ctrl+Alt+Shift+S (Windows/Linux) or Cmd+Shift+A (macOS).
- Select the SDK: Click on Platform Settings in the left pane and then select SDKs.
- Add or Modify an SDK: If you need to add a new Java version, click the + button and choose JDK. If you want to change the version of an existing SDK, select it from the list.
- Set the Compiler Version: In the SDK dialog, you'll find the Compiler dropdown menu. Select the desired Java version from the options.
- Apply Changes: Click Apply and then OK to save the changes.
Example:
Let's say you have a project that requires Java 11 and another project that requires Java 17. You can configure separate SDKs for each project:
- Project 1 (Java 11): Create an SDK named Java 11 and set the compiler version to 11.
- Project 2 (Java 17): Create an SDK named Java 17 and set the compiler version to 17.
Now, when you open each project, IntelliJ will automatically use the corresponding SDK and compiler version.
Additional Tips:
- You can also change the Java compiler version for individual modules within a project.
- To see the current compiler version, go to File > Settings > Build, Execution, Deployment > Compiler.
- Make sure the Java version you want to use is installed on your system.