How do I change language level for all modules in IntelliJ

前端 未结 3 1288
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 02:11

I have a project with MANY modules. We\'re upgrading to Java7, and I want my editor to reflect this. Now all my modules specifically set the language level to Java6, and there a

3条回答
  •  故里飘歌
    2021-02-05 02:25

    As pointed out in the comment by Lambart to the other answer, the solution doesn't work for changing the target version for all the modules altogether.

    Also, observe that setting the target level for the project is fine, but this target version is overridden by the one specified in a module.

    If you, like me, are unlucky and need to work on a 100+ modules Java monolith, then changing modules one by one will be a pain.


    My solution is "annoying" but works under LINUX. I assume in the example that you want to update form 1.5 to 1.8.

    Step 1) You have to go in the .idea folder and look for the file compiler.xml.

    Replace all the target values in the tag , e.g.

    target="1.5" 
    

    to

    target="1.8"
    

    Step 2) go in the project folder and run the following script

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

    to replace all the language level in the modules to be JDK8 compliant.

提交回复
热议问题