【问题标题】:Intellij idea gives java7 errors though compiling in java8 [duplicate]尽管在 java8 中编译,Intellij 的想法给出了 java7 错误 [重复]
【发布时间】:2017-10-19 12:42:02
【问题描述】:

我有一个 maven 项目,并已将 intellij 配置为使用 java 8。我的一位同事推动了一项在接口中使用 default 关键字的更改。自从我同步他的更改后,我的编译一直失败。

我目前很困惑,无法在网上找到答案。

以下是来自 Intellij 的错误消息。目前在我的设备上安装了1.8.0_111-b14 版本的Java 和Intellij 2016.3.4

Information:18/10/17, 1:06 PM - Compilation completed with 1 error and 0 warnings in 3s 442ms
Information:javac 1.8.0_111 was used to compile java sources
Error:(17, 16) java: default methods are not supported in -source 1.7 (use -source 8 or higher to enable default methods)

【问题讨论】:

  • 你的 pom.xml 中有 maven 编译器插件吗?

标签: java maven intellij-idea java-8


【解决方案1】:

知道了。我必须在我的 POM 文件中为 Maven 插件更改和版本。

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

【讨论】:

    【解决方案2】:

    项目结构 > 项目 > 项目 SDK。设置为 1.8。

    如果这没有帮助,项目结构 > 模块,并确保您的模块设置为语言级别 8

    【讨论】:

    • 另外,我会在 Settings -> Build, Excetution, Deployment -> Compiler -> Java Compiler 下将 Target bytecode version 设置为 1.8
    【解决方案3】:

    将以下内容添加到您的 pom.xml:

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    

    这将配置maven传递给JDK进行编译的JDK目标版本

    【讨论】:

      【解决方案4】:

      将您的 java 版本设置为 java8 并执行更新。另外,执行invalidate cache / restart

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-22
        • 1970-01-01
        • 1970-01-01
        • 2018-08-08
        • 2017-08-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多