如何更改IntelliJ中所有模块的语言级别 [英] How do I change language level for all modules in IntelliJ

查看:500
本文介绍了如何更改IntelliJ中所有模块的语言级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多模块的项目.我们正在升级到Java7,我希望我的编辑器能够反映这一点.现在,我所有的模块都专门将语言级别设置为Java6,对于我来说,太多的模块无法更改此设置.如何将所有模块设置为Java7?更好的是,如何设置所有模块以使用项目的语言级别?

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 are too many modules for me to change this setting for each module. How do I set all the modules to Java7? Even better, how do I set all the modules to use the project's language level?

推荐答案

Lambart 在评论中指出另一个答案是,该解决方案无法完全更改所有模块的目标版本.

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.

如果像我一样,您很不幸并且需要​​使用100多个模块的Java独石,那么一劳永逸地更改模块将很痛苦.

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.

我的解决方案是烦人的",但是在LINUX下可以工作.在示例中,我假设您要将表格 1.5 更新为 1.8 .

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

步骤1),您必须进入.idea文件夹并查找文件compiler.xml.

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

替换标签<module>中的所有target值,例如

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

target="1.5" 

target="1.8"

第2步)进入项目文件夹并运行以下脚本

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"

将模块中的所有语言级别替换为JDK8兼容.

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

这篇关于如何更改IntelliJ中所有模块的语言级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆