How to change project language level for all project in Intellij

╄→尐↘猪︶ㄣ 提交于 2019-11-27 15:35:30

问题


I am using Intellij. It is good, but when I create a new project or import a project the default project language level set to 6 (@override in interfaces). But I want to set it 8 (Lambdas, type annotations etc). How can I do that? I have tried change the settings in "Other Settings" -> "Default Project Structure" and the set the project language level to 8, but no luck. Please someone help me. I have added a screen shoot.

  • I am using Intellij 14.0.2

回答1:


I changed the settings to Java 8 as advised above...->Default Project Structure.

It did'nt work!!

I continued not being able to write Lambda's in the editor without errors.

When I created the project, I chose Gradle as the build tool. For some reason my Java/Gradle project had the source compatibility in the build.gradle file set to 1.5 (maybe because my default was originally set to 1.5...I don't know as I did not bother to reproduce it):

apply plugin: 'java'

sourceCompatibility = 1.5

repositories {
    mavenCentral()
}

Changing the sourceCompatibility to 1.8 solved the problem, since the update to the gradle file also triggers a project build.

Word to the wise:

any newbie on Intelij should remember that not selecting either Maven or Gradle in conjunction with your Java project creation will not setup the default package (src/main/test and src/main/java) structures necessary; for eclipse users this is a real head scratcher when first starting to use Intelij.




回答2:


File -> Other Settings -> Default Project Structure...

You can change it in there.

(Edit: It's now called "Structure for New Projects")




回答3:


If it is a maven project, make sure that the following is set.

For example, if you want to use the Java 8 language features (-source 1.8) and also want the compiled classes to be compatible with JVM 1.8 (-target 1.8), you can either add the two following properties, which are the default property names for the plugin parameters:

<project>
  [...]
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  [...]
</project>

For more details check this




回答4:


I had same problem. Changing IntelliJ IDEA setting files (misc.xml, compiler.xml) has not helped. Then I changed language level in two places:

1) File -> Project Structure -> Modules, "Sources" tab, Language level 8 (or higher).

2) Settings -> Build, Execution,Deployment -> Compiler -> Java Compiler -> Target bytecode version (version 1.8)

This worked fine.




回答5:


Same problem but slightly different solution. IntelliJ (2018.1.15) gave me the option to Set Language Level to 6 which I accepted. This added the following to the project .iml file:

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

I was then able to update source & target to 8.




回答6:


I had to edit .idea/misc.xml and change languageLevel="JDK_1_7" to languageLevel="JDK_1_8". I've been unable to change the language level via the ui in osx.

** Intellij 15.0.4




回答7:


I was able to resolve this problem by going to:

File -> Project Structure... And selecting an option from the dropdown under "Project language level"

Hope this helps!



来源:https://stackoverflow.com/questions/29915259/how-to-change-project-language-level-for-all-project-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!