[FIXED] How can I specify the JDK in IntelliJ for storing in Git?

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under
CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.


Question 1: Is it possible to specify JDK for an IntelliJ IDEA project for storing in Git? Currently, I have to clone an IntelliJ Java project from Git and then manually set up JDK in Project Structure. Is it possible to get the JDK automatically set up (selected) for the project in IntelliJ upon project cloning from Git?

Also, related question 2: why do we need to set up the JDK in IntelliJ for the project if we specify the JDK version in the Maven POM file, so it could be selected for the project automatically from those JDKs registered with IntelliJ?


To answer question 1., it’s possible to specify the language level in the pom, such as “1.8” but it’s not possible to specify the specific build of the JDK (e.g. 1.8.0_301) in the pom.

This allows a “general” language level definition that correctly uses java code from different language levels (Overrides, diamonds, lambdas, etc) whilst at the same time allowing you to upgrade the JDK (security update?) at any time without breaking your build.

Remember also that JDK’s are platform dependent, and your java code is portable – it should compile and run on PC, linux and Mac. Specifying a JDK only available for windows would break the concept of portability (which is one of the reasons why java is in such widespread use)

Question 2. If you already have set up the JDK for the language level you need, you don’t need to do it again. Just because the maven pom says “Java 12” doesn’t mean that IntelliJ is smart enough to go and download the correct JDK version – you need to do that 😉

In any case, setting up java 12 is a one-off activity for all your projects (and then updates from time to time) – so don’t sweat it too much.

Answered By – vikingsteve
Answer Checked By – Gilberto Lyons (JavaFixing Admin)


people found this article helpful. What about you?