How do I change language level for all modules in IntelliJ

前端 未结 3 1275
被撕碎了的回忆
被撕碎了的回忆 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 <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.

    0 讨论(0)
  • 2021-02-05 02:25

    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
    0 讨论(0)
  • 2021-02-05 02:40

    The other solutions didn't worked for me, even after modifying by hand the compiler.xmland all the .iml files the the LANGUAGE_LEVEL was still set to "JDK_1_5". This was caused by the maven-compiler-plugin plugin's configuration option.

    Changing it to the following fixed it:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
    

    Hope this solves it for others also.

    0 讨论(0)
提交回复
热议问题