Home > OS >  How can I specify the JDK in IntelliJ for storing in Git?
How can I specify the JDK in IntelliJ for storing in Git?

Time:09-16

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?

CodePudding user response:

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.

  • Related