Unable to compile using Java 1.7 in Jetbrains Inte

2019-02-02 04:58发布

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条回答
小情绪 Triste *
2楼-- · 2019-02-02 05:33

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.

查看更多
叛逆
3楼-- · 2019-02-02 05:39

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)
查看更多
smile是对你的礼貌
4楼-- · 2019-02-02 05:41

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.

查看更多
甜甜的少女心
5楼-- · 2019-02-02 05:44

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

查看更多
贪生不怕死
6楼-- · 2019-02-02 05:45

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

查看更多
▲ chillily
7楼-- · 2019-02-02 05:47

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

查看更多
登录 后发表回答