Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change language level for all modules in IntelliJ

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?

like image 994
Niel de Wet Avatar asked Mar 19 '14 11:03

Niel de Wet


People also ask

How do I change global settings in IntelliJ?

To configure project settings, select IntelliJ IDEA | Preferences on macOS or File | Settings on Windows and Linux from the main menu. Alternatively, you can press Ctrl+Alt+S to show the IDE settings. icon. Other settings are global and apply to all existing projects.

What is project language level in IntelliJ?

As per the documentation within section Exploring the General Project Settings at the IntelliJ Wiki, the project language level impacts the intellisense provided by the IDE. It also dictates the behavior of the compiler being used by IntelliJ when it compiles your Java code as you develop.

How do I change the default settings in IntelliJ?

From the main menu, select File | Manage IDE Settings | Restore Default Settings. Alternatively, press Shift twice and type Restore default settings . Click Restore and Restart.


2 Answers

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 <module>, 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.

like image 189
JeanValjean Avatar answered Sep 26 '22 03:09

JeanValjean


In IntelliJ IDEA 14.0, go to File | Project Structure | Modules (Ctrl+Shift+Alt+S).

The list of modules supports multiple selection so

  • Ctrl click individual modules
  • Shift click range of modules
  • Ctrl-A all modules

Select in the drop-down menu Language level and choose manually the level or "Use project language level".

Similarly to change the language level for the project, select project in the ribbon on the left under Project Settings. A drop down menu is available for Project language level. Choose the level needed. This will set the default for all project modules.

Sources

  • https://www.jetbrains.com/idea/help/project-general-settings-page.html
  • https://www.jetbrains.com/idea/help/modules.html
like image 45
ShooShoSha Avatar answered Sep 26 '22 03:09

ShooShoSha