简体   繁体   中英

IntelliJ IDEA 2016.3 unable to compile with java 7

  • I've recently updated to IntelliJ IDEA 2016.3 and I just noticed that whenever I have a project with a java 7 SDK selected, IntelliJ compiles the project with java 1.8.0_112-release (which must be a compiler bundled with IntelliJ because I have never installed it myself).

  • If I select a java 8 SDK other than the 1.8.0_112-release, IntelliJ compiles with that compiler.

  • If I have a java 7 SDK selected and run a main method in my project, IntelliJ uses that java 7 SDK version to run so the issues seems to only relate to the compiler.

  • I have tried re-installing all my java installations.

  • When I change the SDK I usually only change Project Structure -> Project -> Project SDK , but I also verify that the Language level is correct and that Project Structure -> Modules -> Dependencies -> Module SDK is correct.

  • All settings are default under:

    • Settings -> Build, Execution, Deployment -> Compiler/Java Compiler
  • It seems to me that IntelliJ IDEA 2016.3 is not able to use a java compiler lower than java 8, but my googling attempts have not been able to confirm this.

  • I can also mention that the only thing I haven't tried yet is a hard uninstall of IntelliJ where all my settings are wiped as well. A silent uninstall have been tried.

  • If I try to compile a new Hello World project with a Java 7 SDK this is the output in the Messages tab: Information:Using javac 1.8.0_112-release to compile java sources . If however I set the project SDK to a Java 8 SDK this is the output in the Messages tab: Information:Using javac 1.8.0_45 to compile java sources .

  • Have tried setting Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Project bytecode version to 1.7 without any effect.

  • File -> Other Settings -> Default Project Structure -> Project SDK and Project language level set to the Java 7 SDK. Message tab still displays: Information:Using javac 1.8.0_112-release to compile java sources

Has anyone else experienced this and know what causes this behaviour?

Apparantley this was caused by an issue in IntelliJ as stated in this issue.

It has been resolved as of IntelliJ IDEA version 2016.3.1 and I copy-paste the comment from Eugene Zhuravlev in the youtrack issue to explain how it has been fixed:

A new compiler option has been introduced for javac: File | Settings | Build, Execution, Deployment | Compiler | Java Compiler | "Use compiler from module target JDK when possible". The default value is "on". When this property is enabled and JDK associated with the module differs from the build's own JDK, the build will prefer compiling with the javac from the associated JDK rather than the compiler from the JDK it runs on.

You need to set 2 things:

CTRL + ALT + SHIFT + S --> Project --> Project SDK

CTRL + SHIFT + A --> Type "Java Compiler" --> Target Bytecode Version

there is a distiction between Project Structure and Default Project Structure (the latter is for newly created/checked out Projects).

Default Project Structure hides in File -> Other Settings . There you would have Project SDK and Project Language Level .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM