In this tutorial, we'll learn 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
Then we'll see a popup dialog appear that looks similar to this:
Under the Project SDK section, we'll be able to select a new JDK to use 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, we need to remember that this only affects the JDK used by IntelliJ. Therefore, when running the Java project via the command line, it'll still use the JDK specified in the JAVA_HOME environment variable.
Additionally, changing the Project SDK doesn't change the JVM version of the build tools used. So when using Maven or Gradle within IntelliJ, changing the Project SDK won't change the JVM used for these build tools.
In this article, we illustrated two ways that we can change the Java version used within IntelliJ projects. We also highlighted the caveats we need to be aware of when changing the Java version.
To learn more about IntelliJ's Project Structure, visit the official documentation.