41

While trying to build a project using intelliJ Ultimate 12 I am getting these errors

use -source or higher to enable diamond operator
use -source 7 or higher to enable multi-catch statement

I used the same code with same intelliJ Ultimate 12 on some other system and its working fine there. I want to know what configurations I need to set in my IDE to fix these build issues?

1
  • 5
    in project structure --> project --> project language level, is it set to java 7 correctly?
    – radai
    Feb 2, 2013 at 7:03

7 Answers 7

49

the language level for a project is set in the project structure dialog: project structure dialog you want to make sure you set the language level to java 7, and the sdk accordingly

2
  • 4
    Don't forget a "Rebuild application" to clean.
    – Shad
    Feb 23, 2015 at 21:57
  • 1
    if you see that intellij language level is already set to the correct one -- you might downgrade it and upgrade it again for that to take effect. I had to do this for Intellij 15 after I freshly imported my gradle project.
    – averasko
    Jun 18, 2016 at 1:24
34

In addition to the accepted answer, you may also need to change the language level under Project Structure > Modules > Sources tab.

I also needed to change the java compiler being used at the IDE level under IntelliJ IDEA > Preference > Compiler > Java Compiler to 1.7 from 1.6. The exact location of the setting will vary based on your OS and version of IntelliJ IDEA.

1
  • 1
    THANK YOU, there's so many answers to these kinds of questions that don't mention the compiler
    – notacorn
    Aug 25, 2020 at 15:14
12

For me, it's because the maven-compiler-plugin's source and target is set to 1.6 rather than 1.7 in pom.xml, changing it to 1.7 solved the problem.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.0</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>
4

I had the same problem and was struggling. Auto-import was true, re-import of project was not working and tried all possible options. But finally i found the solution.

"Reimport All Maven Projects" did the trick for me.
You can find the option on the Maven Project tab.


enter image description here

4

None of the above worked for me.

I had to explicitly add the following plugin statement to my pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
    </configuration>
  </plugin>

(Well, IDEA made it for me when I clicked the red help lamp and selected "Set project Java level to 7", so maybe try that if this also doesn't work).

2

If using Gradle as a build automation, set following settings in build.gradle and re-import your project:

sourceCompatibility = 1.7

targetCompatibility = 1.7

0

For IntelliJ IDEA Community 2018.2:

  • In the project tool window, right-click on the project name to get to the Project Structure menu.
  • Set Language Level to whatever version you want, and rebuild project again.

You can also use F4 as shortcut to get to the same menu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.