Reputation: 19905
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?
Upvotes: 159
Views: 126062
Reputation: 91
nothing from other answers helped, except of installing new Intellij Idea version
Upvotes: 0
Reputation: 670
There seems a few places that effect the source (byte code) version in IntelliJ:
• IntelliJ > Preferences >Build Exce Deploy > Java Compiler
◦ Module > Target Bytecode Version
• File > Project Structure
◦ Project > Language Level & SDK
◦ Module > Language Level
• Maven Properties
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
Upvotes: 0
Reputation: 6104
I managed to fix this by changing settings for new projects:
File -> New Projects Settings -> Settings for New Projects -> Java Compiler -> Set the version
File -> New Projects Settings -> Structure for New Projects -> Project -> Set Project SDK + set language level
Remove the projects
Import the projects
Upvotes: 1
Reputation: 748
In IntelliJ Community Edition 2019.02, Changing the following settings worked for me
Update File->Project structure->Project Settings->Project->Project Language level to Java 11 (update to the java version that you wish to use in your project) using drop down.
Update File->Project structure->Project Settings->Modules->Language level
Update File->Settings->Build,Execution,Deployment -> Compiler -> Java Compiler-> Project ByteCode Version to java 11.
Update Target version for all the entries under File->Settings->Build,Execution,Deployment -> Compiler -> Java Compiler-> Per module Byte Code Version.
Upvotes: 3
Reputation: 24324
One more thing that could cause this is having incorrect version
of the <parent>
project.
In my case it was pointing to a non-existing project and for some reason IntelliJ downgraded version in settings to 1.5 and later when I fixed it, it was still interpreting target code version as 5 (despite setting it to 11).
Upvotes: 1
Reputation: 4837
I had the following property working for me in IntelliJ 2017
<properties>
<java.version>1.8</java.version>
</properties>
Upvotes: 0
Reputation: 2664
File->Project structure->Project Settings->Project->Project Language level
File->Project structure->Project Settings->Modules->Language level
Change level using drop down
Upvotes: 12
Reputation: 94
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.
Upvotes: 4
Reputation: 5808
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>
Upvotes: 15
Reputation: 560
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.
Upvotes: 2
Reputation: 8046
[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.
Upvotes: 52
Reputation: 3912
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>
Upvotes: 22
Reputation: 18931
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.
Upvotes: 163
Reputation: 4259
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
Upvotes: 120
Reputation: 201437
First, you need to change the "project bytecode version" under File > Settings
, Compiler > Java Compiler
Second, do a full rebuild.
Upvotes: 2