尽管设置为 1.7,但 IntelliJ IDEA 13 仍使用 Java 1.5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21006136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ IDEA 13 uses Java 1.5 despite setting to 1.7
提问by PNS
Despite specifying JDK 1.7 in all project settings (including in File -> Project Structure -> Project :: Project SDK
), the following error is produced by IntelliJ 13
when trying to compile some simple Java 7 code which does use the diamond operator:
尽管在所有项目设置(包括 in File -> Project Structure -> Project :: Project SDK
)中指定了 JDK 1.7 ,但IntelliJ 13
在尝试编译一些使用菱形运算符的简单 Java 7 代码时会产生以下错误:
java: diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
Is there any other place in the configuration where the expected -source 7
option should be enabled?
配置中是否还有其他地方-source 7
应该启用预期的选项?
采纳答案by Djordje Ivanovic
If nothing of this helps (my case), you can set it in your pom.xml, like this:
如果这没有任何帮助(我的情况),您可以在 pom.xml 中设置它,如下所示:
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
As this cool guy mentioned here: https://stackoverflow.com/a/25888116/1643465
正如这里提到的这个很酷的家伙:https: //stackoverflow.com/a/25888116/1643465
回答by Peter Gromov
Please check your project/module language levels (Project Structure | Project; Project Structure | Modules | module-name | Sources). You might also want to take a look at Settings | Compiler | Java Compiler | Per-module bytecode version.
请检查您的项目/模块语言级别(项目结构 | 项目;项目结构 | 模块 | 模块名称 | 来源)。您可能还想看看设置 | 编译器 | Java编译器| 每个模块的字节码版本。
Set also this:
还设置这个:
File -> Project Structure -> Modules :: Sources (next to Paths and Dependencies) and that has a "Language level" option which also needs to be set correctly.
文件 -> 项目结构 -> 模块 :: 源(在路径和依赖项旁边)并且具有“语言级别”选项,该选项也需要正确设置。
回答by Elliott Frisch
First, you need to change the "project bytecode version" under File > Settings
, Compiler > Java Compiler
首先,您需要更改下的“项目字节码版本” File > Settings
,Compiler > Java Compiler
Second, do a full rebuild.
其次,进行全面重建。
回答by OlgaMaciaszek
Alternatively, you can apply maven-compiler-plugin with appropriate java version by adding this to your pom.xml:
或者,您可以通过将其添加到 pom.xml 来应用具有适当 Java 版本的 maven-compiler-plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
回答by Birchlabs
[For IntelliJ IDEA 2016.2]
[适用于 IntelliJ IDEA 2016.2]
I would like to expand upon part of Peter Gromov's answerwith an up-to-date screenshot. Specifically this particular part:
我想用最新的屏幕截图来扩展Peter Gromov 的部分答案。特别是这个特定部分:
You might also want to take a look at Settings | Compiler | Java Compiler | Per-module bytecode version.
您可能还想看看设置 | 编译器 | Java编译器| 每个模块的字节码版本。
I believe that (at least in 2016.2): checking out different commits in git
resets these to 1.5.
我相信(至少在 2016.2 中):检查不同的提交将git
这些重置为 1.5。
回答by jordom
I have same problem but with different situation. I can compile without any issue with maven in command line (mvn clean install
), but in Intellij I always got "java: diamond operator is not supported in -source 1.5"
compile error despite I have set the maven-compiler-plugin with java 1.8 in the pom.xml.
我有同样的问题,但情况不同。我可以在命令行 ( mvn clean install
) 中使用 maven 进行编译而没有任何问题,但是在 Intellij 中,"java: diamond operator is not supported in -source 1.5"
尽管我在 pom.xml 中使用 java 1.8 设置了 maven-compiler-plugin ,但我总是遇到编译错误。
It turned out I have remote repository setting in my maven's settings.xml which the project depends on, but Intellij uses his own maven which doesn't have same setting with my local maven.
原来我在项目所依赖的 maven 的 settings.xml 中有远程存储库设置,但 Intellij 使用他自己的 maven,它与我的本地 maven 没有相同的设置。
So my solution was changing the Intellij's maven setting (Settings -> Build, execution, Deployment -> Maven -> Maven home directory
) to use the local maven.
所以我的解决方案是更改 Intellij 的 maven 设置 ( Settings -> Build, execution, Deployment -> Maven -> Maven home directory
) 以使用本地 maven。
回答by Amit Kaneria
I tried making changes to Intellij IDEA as below:
我尝试对 Intellij IDEA 进行如下更改:
1.
1.
File >> Settings >> Build, Execution, Deployment >> Compiler >> Java Compiler >> project bytecode version: 1.8 >> Per-module bytecode version: 1.8
2.
2.
File >> Project Structure >> Project Settings >> Project >> SDK : 1.8, Project Language : 8 - Lambdas
File >> Project Structure >> Project Settings >> Modules >> abc : Language level: 8 - Lambdas
but nothing worked, it reverted the versions to java 1.5 as soon as I saved it.
但没有任何效果,一旦我保存它,它就会将版本恢复为 java 1.5。
However, adding below lines to root(project level) pom.xml worked me to resolve above issue: (both of the options worked for me)
但是,将以下几行添加到 root(项目级别)pom.xml 帮助我解决了上述问题:(这两个选项都对我有用)
Option 1:
选项1:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Option 2:
选项 2:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
回答by Saideep Sambaraju
In your command line(Unix terminal) Go to your project root folder, and do this
在您的命令行(Unix 终端)中,转到您的项目根文件夹,然后执行此操作
find . -type f -name '*.iml' -exec sed -i '' s/JDK_1_5/JDK_1_8/g {} +
This will change the language level property in all your project .iml files from java 1.5 to java 1.8.
这会将所有项目 .iml 文件中的语言级别属性从 java 1.5 更改为 java 1.8。
回答by ketankk
File->Project structure->Project Settings->Project->Project Language level
文件->项目结构->项目设置->项目->项目语言级别
File->Project structure->Project Settings->Modules->Language level
文件->项目结构->项目设置->模块->语言级别
Change level using drop down
使用下拉菜单更改级别
回答by H.Rabiee
I had the following property working for me in IntelliJ 2017
我在 IntelliJ 2017 中有以下属性为我工作
<properties>
<java.version>1.8</java.version>
</properties>