欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

错误:java:javacTask:源版本8需要目标版本1.8

程序员文章站 2022-07-14 10:42:46
...

本文翻译自:Error:java: javacTask: source release 8 requires target release 1.8

Using IntelliJ IDE can't compile any projects. 使用IntelliJ IDE无法编译任何项目。 Screenshots of settings below: 以下设置的屏幕截图:

Used JDK: 使用JDK:

错误:java:javacTask:源版本8需要目标版本1.8

Project SDK and Language level: 项目SDK和语言级别:

错误:java:javacTask:源版本8需要目标版本1.8

Language Level: 语言水平:

错误:java:javacTask:源版本8需要目标版本1.8

Anybody have any ideas? 有人有什么想法吗?


#1楼

参考:https://stackoom.com/question/21PO4/错误-java-javacTask-源版本-需要目标版本


#2楼

This looks like the kind of error that Maven generates when you don't have the compiler plugin configured correctly. 这看起来就像Maven在没有正确配置编译器插件时生成的错误。 Here's an example of a Java 8 compiler config. 这是Java 8编译器配置的示例。

<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<!-- ... -->

    <build>
        <plugins>
            <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>
        </plugins>
    </build>

<!-- ... -->

</project>

#3楼

  1. File > Settings > Build, Execution, Deployment > Compiler > Java Compiler 文件>设置>构建,执行,部署>编译器> Java编译器
  2. Change Target bytecode version to 1.8 of the module that you are working for. 目标字节码版本更改为您正在使用的模块的1.8

If you are using Maven 如果你使用Maven

Add the compiler plugin to pom.xml under the top-level project node: 将编译器插件添加到*project节点下的pom.xml

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

(Hoisted from the comments.) (从评论中提到。)

Note: If you don't mind reimporting your project, then the only thing you really need to do is change the pom and reimport the project, then IntelliJ will pick up the correct settings and you don't have to manually change them. 注意:如果您不介意重新导入项目,那么您真正需要做的就是更改pom并重新导入项目,然后IntelliJ将选择正确的设置,您不必手动更改它们。


#4楼

You need to go to Settings and set under the Java compiler the following: 您需要转到Settings并在Java编译器下设置以下内容: 错误:java:javacTask:源版本8需要目标版本1.8

also check the Project Settings 还要检查项目设置


#5楼

There are two ways to solve this problem: 有两种方法可以解决这个问题:

  1. Set settings (File -> Settings -> Build, Execution, Deployment -> Java Compiler) : 设置设置(File -> Settings -> Build, Execution, Deployment -> Java Compiler) 错误:java:javacTask:源版本8需要目标版本1.8
  2. Add a build section to your pom.xml : pom.xml添加构建部分: 错误:java:javacTask:源版本8需要目标版本1.8

#6楼

The quicketst way I found: 我找到的最快捷的方式:

  • press: CTRL + SHIFT + A (For Mac + SHIFT + A ) 按: CTRL + SHIFT + A (对于Mac⌘ + SHIFT + A
  • type: java compiler 类型: java compiler
  • press: ENTER 按: ENTER

In the setting window set the Target bytecode to 1.8 在设置窗口中,将目标字节码设置为1.8

(or 9 for java9) (或java9的9