24
votes

Using Jetbrains 11.2 project based on a Maven project. Then I required to move to 1.7. I have 1.7 installed , I updated my pom.xml and I can rebuild the whole package using maven okay.

I've modified every setting I can see in Intelli Projects settings regarding Java version

  • Project SDk
  • Project language Level
  • Modules Languages/Sources/Language Level
  • Modules Languages/Dependencies/Module SDK

but I cannot get it to compile a file it complains:

Error:javac target release of 1.6 conflicts with source release 1.7

I then tried on my other dev machine using the same codebase but a different Intellij Project and on this I get a similar error:

Error:javac: source release 1.7 requires target release 1.7

I cannot see anything else to change in order to get this working.

6

6 Answers

38
votes

Doh, found it

File/Settings/Java Compiler/Additional command line parameters

changed from -target 1.6 to -target 1.7

Does seem wierd for it to be here though, disconnected from the rest of the related options.

13
votes

As an alternative solution, which worked for me is to check in Module Settings the Language Level property. It was set to 8.0 Lambdas and changed to 6.0 @Overrides in interfaces, and after that compilation worked without error.

9
votes

IntelliJ 2017 (also 15 or 2016)

You can change compiler version here:

File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler

Now change Target bytecode version to desired one.

IntelliJ 13 or 14

You can change compiler version here:

 Intellij IDEA -> Preferences -> Compiler -> Java Compiler
 -> Project bytecode version -> 1.7 (for example)
7
votes

For IntelliJ 12, I solved this by opening the File:Project Structure and updating the Project SDK to 1.7 and the Project language level to "7.0 - Diamonds, ARM, multi-catch etc."

If you don't have IntelliJ configured with JDK 1.7, add it with the "New" button. Select type "JDK".

1
votes

Another potential fix is to make sure that your build file has the version hardcoded as seen here

    <javac target="1.7" source="1.7" ... />

as opposed to

<property name="java.version" value="1.7" />
<javac target="${java.version}" source="${java.version}" ... />

Though this could be due to my misunderstanding of how variables work in build files. You would think that this would make sense though

1
votes

I encountered the same problem. I solved it by Intellij IDEA -> Preferences -> Compiler -> Java Compiler -> Project bytecode version -> 1.7 & Target bytecode version -> 1.7