How to change from -source 1.6 to -source 7 in IntelliJ IDEA

JavaIntellij Idea

Java Problem Overview


I' trying to build a in IntelliJ IDEA project that is not mine and I got the following error:

java: diamond operator is not supported in -source 1.6 (use -source 7 or higher to enable diamond operator)

How do I change this setting in IntelliJ IDEA?

Java Solutions


Solution 1 - Java

Ctrl+Alt+Shift+S (Project Structure icon)

Then change Project language level

Solution 2 - Java

I know the OP uses IntelliJ IDEA, but Android Studio is based on IntelliJ IDEA, so I wanna say one more word.

If you use Android Studio, command+;(for Mac) or File->Project Structure, then in the open window follow the settings:

enter image description here

Solution 3 - Java

And, if you're working with a maven project, for sanity, remember to set the java version in the pom too.

<build>
	<plugins>
		<plugin>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<source>1.7</source>
				<target>1.7</target>
			</configuration>
		</plugin>
	</plugins>
</build>

Solution 4 - Java

File -> Project Structure -> Sources -> Language level

You will have to reload IDEA

Solution 5 - Java

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

Change level using drop down.

Otherwise, If you are using maven for build,

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
</build>

Solution 6 - Java

For me, changing the Language Level in Project Structure and restarting IDEA didn't help.

I had to edit the build.gradle in core module and change the source compatibility from 1.6 to 1.7:

apply plugin: "java"

sourceCompatibility = 1.7 //changed from 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = [ "src/" ]


eclipse.project {
    name = appName + "-core"
}

Build -> Clean Project

Solution 7 - Java

For me, above answers didn't work, although they helped me solve my issue. At module level build.gradle do the following:

compileOptions {
        // I've changed below values from VERSION_1_6 to VERSION_1_7
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

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
QuestionEl MarceView Question on Stackoverflow
Solution 1 - JavaOri DarView Answer on Stackoverflow
Solution 2 - JavaAllenView Answer on Stackoverflow
Solution 3 - JavaSarah PhillipsView Answer on Stackoverflow
Solution 4 - JavasenseiwuView Answer on Stackoverflow
Solution 5 - JavaketankkView Answer on Stackoverflow
Solution 6 - JavaNeerkoliView Answer on Stackoverflow
Solution 7 - JavaNecipAllefView Answer on Stackoverflow