IntelliJ IDEA 13 uses Java 1.5 despite setting to 1.7

JavaIntellij IdeaCompilation

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

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

Solution 3 - Java

[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.

Per-module bytecode version

Solution 4 - Java

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>

Solution 5 - Java

I tried making changes to Intellij IDEA as below:

File >> Settings >> Build, Execution, Deployment >> Compiler >> Java Compiler >> project bytecode version: 1.8 >> Per-module bytecode version: 1.8
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>

Solution 6 - Java

File->Project structure->Project Settings->Project->Project Language level

File->Project structure->Project Settings->Modules->Language level

Change level using drop down

Solution 7 - Java

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.

Solution 8 - Java

In IntelliJ Community Edition 2019.02, Changing the following settings worked for me

  1. 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.

  2. Update File->Project structure->Project Settings->Modules->Language level

  3. Update File->Settings->Build,Execution,Deployment -> Compiler -> Java Compiler-> Project ByteCode Version to java 11.

  4. Update Target version for all the entries under File->Settings->Build,Execution,Deployment -> Compiler -> Java Compiler-> Per module Byte Code Version.

Solution 9 - Java

First, you need to change the "project bytecode version" under File > Settings, Compiler > Java Compiler

Second, do a full rebuild.

Solution 10 - Java

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.

Solution 11 - Java

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).

Solution 12 - Java

I managed to fix this by changing settings for new projects:

  1. File -> New Projects Settings -> Settings for New Projects -> Java Compiler -> Set the version

  2. File -> New Projects Settings -> Structure for New Projects -> Project -> Set Project SDK + set language level

  3. Remove the projects

  4. Import the projects

Solution 13 - Java

I had the following property working for me in IntelliJ 2017

  <properties>
        <java.version>1.8</java.version>       
  </properties>

Solution 14 - Java

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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPNSView Question on Stackoverflow
Solution 1 - JavaPeter GromovView Answer on Stackoverflow
Solution 2 - JavaDjordje IvanovicView Answer on Stackoverflow
Solution 3 - JavaBirchlabsView Answer on Stackoverflow
Solution 4 - JavaOlgaMaciaszekView Answer on Stackoverflow
Solution 5 - JavaAmit KaneriaView Answer on Stackoverflow
Solution 6 - JavaketankkView Answer on Stackoverflow
Solution 7 - JavaSaideep SambarajuView Answer on Stackoverflow
Solution 8 - JavaKhyati ElhanceView Answer on Stackoverflow
Solution 9 - JavaElliott FrischView Answer on Stackoverflow
Solution 10 - JavajordomView Answer on Stackoverflow
Solution 11 - JavasyntagmaView Answer on Stackoverflow
Solution 12 - JavaDanylo ZatorskyView Answer on Stackoverflow
Solution 13 - JavaH.RabieeView Answer on Stackoverflow
Solution 14 - JavaSydMKView Answer on Stackoverflow