Update java language level for many modules in Intellij IDEA

Last modified by Guillaume Delhumeau on 2023/03/09 11:37

Mar 26 2019

I have a problem with Intellij IDEA. It's a wonderful IDE, and I use it everyday for my job at XWiki. But I have found a bug that I have reported that is very annoying. Frequently, it changes the "language level" of my java modules to 1.5, while my project is actually written with Java 1.8. It is a pain since I have hundreds of modules, and this setting must be changed to each individual module manually.

To work around this problem, I have found a solution on stackoverflow that I will share with you.

First, you need to shut down your IDE.

Second step: go to the .idea folder inside your project, and open compiler.xml

Replace all the target values in the tag <module>, e.g.

target="1.5" 

to

target="1.8"

Third step: go in the project folder and run the following commands

find . -type f -name "*.iml" -print0 | xargs -0 sed -i "s/JDK_1_5/JDK_1_8/g"
...