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?
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.
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.
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.
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.
In IntelliJ IDEA 14.0, go to File | Project Structure | Modules (Ctrl+Shift+Alt+S).
The list of modules supports multiple selection so
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With