可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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:
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?
回答1:
If nothing of this helps (my case), you can set it in your pom.xml, like this:
<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
回答2:
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.
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.
回答3:
[For IntelliJ IDEA 2016.2]
I would like to expand upon part of Peter Gromov's answer with an up-to-date screenshot.
Specifically this particular part:
You might also want to take a look at Settings | Compiler | Java Compiler | Per-module bytecode version.
I believe that (at least in 2016.2): checking out different commits in git
resets these to 1.5.
回答4:
Alternatively, you can apply maven-compiler-plugin with appropriate java version by adding this to your pom.xml:
<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>
回答5:
File->Project structure->Project Settings->Project->Project Language level
File->Project structure->Project Settings->Modules->Language level
Change level using drop down
回答6:
I tried making changes to Intellij IDEA as below:
1.
File >> Settings >> Build, Execution, Deployment >> Compiler >> Java Compiler >> project bytecode version: 1.8 >> Per-module bytecode version: 1.8
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.
However, adding below lines to root(project level) pom.xml worked me to resolve above issue: (both of the options worked for me)
Option 1:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Option 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>
回答7:
In your command line(Unix terminal) Go to your project root folder, and do this
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.
回答8:
First, you need to change the "project bytecode version" under File > Settings
, Compiler > Java Compiler
Second, do a full rebuild.
回答9:
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.
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.
So my solution was changing the Intellij's maven setting (Settings -> Build, execution, Deployment -> Maven -> Maven home directory
) to use the local maven.
回答10:
I had the following property working for me in IntelliJ 2017
<properties>
<java.version>1.8</java.version>
</properties>