How can I add IntelliJ IDEA project JDK setting to Git?

249 Views Asked by At

A common pain point with IntelliJ IDEA is correctly configuring the JDK for each project you work on every time you clone the repository or lose the .idea folder.

I want to include the JDK settings in Git to make it easier, especially for new developers, to get up and running. We all agreed to use Coretto 1.8.

First, I added .idea/compiler.xml, which specifies the project language level:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="CompilerConfiguration">
    <bytecodeTargetLevel target="1.8" />
  </component>
</project>

Next, I added .idea/misc.xml, which specifies the project JDK:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ExternalStorageConfigurationManager" enabled="true" />
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK" />
</project>

Then I deleted the ~/.jdks directory, cleaned the project directory with git clean -fdx and reopened the project in IntelliJ. It correctly restored the language level to 1.8 but downloaded Corretto 11 and changed the contents of .idea/misc.xml to:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ExternalStorageConfigurationManager" enabled="true" />
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="corretto-11" project-jdk-type="JavaSDK" />
</project>

Do I need to include some other file or is there some other trick?

0

There are 0 best solutions below