The number of places you can find the Java version in Intellij

Published on March 8, 2024

Having trouble porting to the latest version of Java? Or trying to juggle projects that use different versions of Java? There are some pain points when trying to handle these in Intellij and you get vague errors that don’t point you in the right direction. So here are some pointers to help overcome issues you may come across.

Project Structure

Project SDK

Under File -> Project Structure -> Project -> SDK you will find a list of Java versions to choose from. This list is populated from the SDKs tab on the left side under the heading Platform Settings. If you don’t find the Java version you want, you can go to the SDKs tab and click on the + button towards the top to download or add an SDK already downloaded onto your machine.

To slightly confuse things a bit more, there is an additional field for Language Level. What does language level mean? Shouldn’t it just be the same?

Language level defines coding assistance features that the editor provides. Language level can differ from your project SDK. For example, you can use the JDK 9 and set the language level to 8. This makes the bytecode compatible with Java 8, while inspections make sure you don’t use constructs from Java 9.
- Jetbrains https://www.jetbrains.com/help/idea/project-settings-and-structure.html#language-level

In essence, it allows you to apply syntax highlighting from IntelliJ for a different version of Java. Maybe you don’t want your team to apply the latest Java syntax and patterns quite yet. I don’t know, go figure!

Project Modules

Given your choice of the Project SDK, this should be applied to all modules in your project under File -> Project Structure -> Project Structure -> Modules. You could have different versions of Java applied to your modules by altering it here.

Preferences

Lucky for us, we are granted a search box! Let’s first see if we put in java what comes back.

Ok, this is a long list. It conflicts with some of the Javascript settings but that is okay. Some didn’t show up in the initial search. They have crept through via the use of setting names like JVM, JRE or JDK.

Maven

Maven has two places where you can define the Java version, inside of Importing and Runner.

Gradle

Gradle JVM is the place to configure for Gradle.

SBT

Implicitly defined for SBT, but under JVM -> JRE you define the Java version.

Java Compiler

The first reference to a version of Java comes from the Builder, Execution, Deployment -> Compiler -> Java Compiler section. Here we can see the version used for generating the bytecode. This could be further refined at a module level.

Kotlin Compiler

If you are using Kotlin, you will find a Target JVM version setting under Builder, Execution, Deployment -> Compiler -> Kotlin Compiler section.

Scala Compile Server

If you are using Scala, you will find JDK setting under Builder, Execution, Deployment -> Compiler -> Scala Compiler -> Scala Compile Serversection

Run/Debug Configurations

So far we have come across the settings used for building and compiling with different versions of Java. Now what about when we run our application? Intellij has some additional places where this can be defined.

Under Run -> Edit Configurations, if you have an Application defined, you will find a screen similar to below where you can define the Java version to build and run your application.

Conclusion

These are most (not sure if all) of the places where you can find the Java version to use for your application when using Intellij. It might be a bit convoluted as you try to navigate all the options, but it shines some light into the stages required to build and run your application. 99% of the time, you don’t even notice these stages and everything runs smoothly. Then the 1% where it doesn’t follow the happy path, you find yourself in the depths of hell.

Seemingly random error messages, not knowing what was updated in the background that could cause this disruption, pulling your hair out as it becomes ungoogleable since you cannot explain your full local development environment setup in 10 words or less. Not even ChatGPT could come and rescue you. Instead, you work from those tiny golden snippets inside StackOverflow or long-forgone niche tech forums to give you hints as to how you can resolve your issue. Okay, enough rambling.

TLDR: Follow the pictures.