简体   繁体   English

如何在Intellij中更改所有项目的项目语言级别

[英]How to change project language level for all project in Intellij

I am using Intellij. 我正在使用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). 这很好,但是当我创建一个新项目或导入项目时,默认项目语言级别设置为6(接口中的@override)。 But I want to set it 8 (Lambdas, type annotations etc). 但是我想把它设置为8(Lambdas,类型注释等)。 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. 我尝试更改“其他设置” - >“默认项目结构”中的设置,并将项目语言级别设置为8,但没有运气。 Please someone help me. 请有人帮助我。 I have added a screen shoot. 我添加了一个屏幕截图。 在此输入图像描述

  • I am using Intellij 14.0.2 我正在使用Intellij 14.0.2

File -> Other Settings -> Default Project Structure... 文件 - >其他设置 - >默认项目结构...

You can change it in there. 你可以在那里改变它。

(Edit: It's now called "Structure for New Projects") (编辑:现在称为“新项目的结构”)

If it is a maven project, make sure that the following is set. 如果是maven项目,请确保已设置以下项目。

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: 例如,如果要使用Java 8语言功能(-source 1.8)并且还希望编译的类与JVM 1.8(-target 1.8)兼容,则可以添加以下两个属性,这是默认属性插件参数的名称:

<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 有关详细信息,请检查

I had same problem. 我有同样的问题。 Changing IntelliJ IDEA setting files (misc.xml, compiler.xml) has not helped. 更改IntelliJ IDEA设置文件(misc.xml,compiler.xml)没有帮助。 Then I changed language level in two places: 然后我改变了两个地方的语言水平:

1) File -> Project Structure -> Modules, "Sources" tab, Language level 8 (or higher). 1)文件 - >项目结构 - >模块,“源”选项卡,语言级别8(或更高)。

2) Settings -> Build, Execution,Deployment -> Compiler -> Java Compiler -> Target bytecode version (version 1.8) 2)设置 - >构建,执行,部署 - >编译器 - > Java编译器 - >目标字节码版本(版本1.8)

This worked fine. 这很好。

I changed the settings to Java 8 as advised above...-> Default Project Structure . 我按照上面的建议将设置更改为Java 8 ...-> 默认项目结构

It did'nt work!! 它没有工作!!

I continued not being able to write Lambda's in the editor without errors. 我继续无法在编辑器中编写Lambda而没有错误。

When I created the project, I chose Gradle as the build tool. 当我创建项目时,我选择Gradle作为构建工具。 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): 出于某种原因,我的Java / Gradle项目将build.gradle文件中的源兼容性设置为1.5(可能因为我的默认设置最初设置为1.5 ...我不知道因为我没有费心去重现它):

 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. sourceCompatibility更改为1.8解决了问题,因为对gradle文件的更新也会触发项目构建。

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; Intelij上的任何新手都应该记住,不选择Maven或Gradle与Java项目创建一起不会设置必要的默认包(src / main / test和src / main / java)结构; for eclipse users this is a real head scratcher when first starting to use Intelij. 对于eclipse用户来说,这是第一次开始使用Intelij时的头脑。

Same problem but slightly different solution. 同样的问题但解决方案略有不同 IntelliJ (2018.1.15) gave me the option to Set Language Level to 6 which I accepted. IntelliJ(2018.1.15)给了我选择将语言水平设置为6,我接受了。 This added the following to the project .iml file: 这将以下内容添加到项目.iml文件中:

<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. 然后我能够将源和目标更新为8。

I had to edit .idea/misc.xml and change languageLevel="JDK_1_7" to languageLevel="JDK_1_8" . 我必须编辑.idea/misc.xml并将languageLevel="JDK_1_7"更改为languageLevel="JDK_1_8" I've been unable to change the language level via the ui in osx. 我无法通过osx中的ui更改语言级别。

** Intellij 15.0.4 ** Intellij 15.0.4

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! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM