Paul Taylor
Paul Taylor

Reputation: 13210

Unable to compile using Java 1.7 in Jetbrains Intellij after moving from 1.6 to 1.7 (maven based project)

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

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.

Upvotes: 24

Views: 46003

Answers (6)

Yan
Yan

Reputation: 11

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

Upvotes: 1

kiedysktos
kiedysktos

Reputation: 4100

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)

Upvotes: 9

Heather92065
Heather92065

Reputation: 7893

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

Upvotes: 7

Merlin -they-them-
Merlin -they-them-

Reputation: 2960

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

Upvotes: 1

Gyuri Majercsik
Gyuri Majercsik

Reputation: 2253

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.

Upvotes: 13

Paul Taylor
Paul Taylor

Reputation: 13210

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.

Upvotes: 38

Related Questions