1. Overview
In this tutorial, we'll look at how to change the JDK version in IntelliJ projects. This will work on both Community and Ultimate Editions of IntelliJ.
2. Project Structure Settings
IntelliJ stores the JDK version used by the project within its Project Structure. There are two ways to locate this:
- Via menu navigation:
- Navigating to File -> Project Structure
- Via keyboard shortcut:
- For OSX, we press ⌘ + ;
- For Windows, we press Ctrl + Shift + Alt + S
We'll then see a popup dialog appear that looks similar to this:
Under the Project SDK section, you will be able to select a new JDK that will be used for the project via the combo box. After updating to a new version of Java, the project will begin reindexing its source files and libraries to ensure that autocompletion and other IDE features are synchronized.
3. Common Gotchas
When changing the JDK, one should remember that this only affects the JDK used by IntelliJ. Therefore, when running the Java project via the command line, it will still use the JDK specified in the JAVA_HOME environment variable.
Additionally, changing the Project SDK does not change the JVM version of the build tools used as well. So when using Maven or Gradle within IntelliJ, changing the Project SDK will not change the JVM used for these build tools.
4. Conclusion
In this tutorial, we illustrated two ways in which one could change the Java version used within IntelliJ projects. In addition, we also highlighted that there are some caveats to be aware of when changing the Java version.
To learn more about IntelliJ's Project Structure, visit their documentation link.