java - Intellij 坚持使用 javac 11.0.3 而不是 Java 7 进行编译

标签 java intellij-idea

我有一个包含许多模块的项目,所有这些模块都需要使用 Java 7 进行编译。我已确保我所知道的每个设置都指向该版本的 Java,但不知何故,每次我重建项目时得到:

Information:javac 11.0.3 was used to compile java sources

后跟错误列表:

Warning:(86, 25) java: as of release 9, '_' is a keyword, and may not be used as an identifier

Error:(86, 25) java: cannot find symbol
  symbol:   class _
  location: class com.(...)`

以下其他问题,例如:

Can't resolve -source errors on IntelliJ with regards to Project Language Level

IntelliJ IDEA tells me "Error:java: Compilation failed: internal java compiler error idea"

我尝试过这些设置:

  • 在项目结构 -> 项目 -> 项目 SDK 下:1.7
  • 项目结构 -> 项目语言级别 -> 7 - Diamonds、ARM、multi-catch 等
  • 在项目结构 -> 模块下检查每个模块,这并不有趣,因为大约有 50 个。“源”选项卡 -> 语言级别:项目 detaulf(7 - 钻石、ARM、多捕获等)
  • 项目结构 -> 模块,每个“依赖项”选项卡 -> 模块 SDK:项目 SDK (1.7)
  • 项目结构 -> SDK:它列出了 IDEA 内置的 Java 11,所以我删除了它,只留下:1.7
  • 设置 -> Java 编译器 -> 使用编译器:Javac
  • 设置 -> Java 编译器 -> 尽可能使用模块目标 JDK 的编译器:未选中
  • 设置 -> Java 编译器 -> 每个模块字节码版本:所有模块设置为 1.7

我正在运行最新版本的 IntelliJ IDEA:

IntelliJ IDEA 2019.2 (Ultimate Edition) Build #IU-192.5728.98, built on July 23, 2019

这是 IDEA 的错误吗?

最佳答案

以下是 Intellij 选择 java 11 的原因: https://www.jetbrains.com/help/idea/configuring-build-jdk.html

IntelliJ IDEA checks all JDKs that are used in the project: the JDKs that are defined on both the project and module levels.

IntelliJ IDEA calculates the latest of these JDKs. This is necessary to make sure that all modules can be compiled.

If the version of the latest JDK configured is lower than 1.6, IntelliJ IDEA will pick the JDK version that is used for running the IDE. This limitation is related to the fact that the compiler API used by IntelliJ IDEA for building projects is supported starting from JDK 1.6.

这就是为什么 switching the boot JDK to JDK8重新启用旧 java 类的编译。

关于java - Intellij 坚持使用 javac 11.0.3 而不是 Java 7 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57490341/

相关文章:

java - 如何将 Groovy 脚本添加到具有经典 Maven 结构的 Java 项目中?

java - 我们可以在java中将任何字符串日期值转换为日期yyyy-MM-dd吗?

java - Eclipse包名以com开头

java - 部署在 Tomcat 上的 Spring MVC 应用程序无法在 IntelliJ 上运行

java - 如何在Java代码中查找参数为复合表达式的方法的用法?

java - Intellij Idea中使用 "Runtime.getRuntime().exec"方法时如何设置JAVA_HOME?

java - 是否可以在 JSP 中显示 Swing 组件?

java - java中如何让相机朝它所面对的方向移动?

java - 使用 shell 命令传递 Python/JAVA/Perl 选项

intellij-idea - IntelliJ IDEA-显示方法帮助/说明