Java 行家。-source 1.5 不支持 lambda 表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32923586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:02:20  来源:igfitidea点击:

maven. lambda expressions are not supported in -source 1.5

javamavenlambda

提问by gstackoverflow

I use maven to build my project.

我使用 maven 来构建我的项目。

I have following configuration:

我有以下配置:

D:\freelance\polyndrom>mvn -verion Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T00:58:1 0+04:00) Maven home: C:\Program Files\apache\apache-maven-3.2.3 Java version: 1.8.0_25, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.8.0_25\jre Default locale: ru_RU, platform encoding: Cp1251 OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"

D:\freelance\polyndrom>mvn -verion Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T00:58:1 0+04:00) Maven 主页: C\3.2\Program Maven 文件\-apachem\ 3 Java 版本:1.8.0_25,供应商:Oracle Corporation Java 主页:C:\Program Files\Java\jdk1.8.0_25\jre 默认语言环境:ru_RU,平台编码:Cp1251 操作系统名称:“windows 7”,版本:“6.1 ", 拱门: "amd64", 家庭: "dos"

but when I compile project I see following errors:

但是当我编译项目时,我看到以下错误:

lambda expressions are not supported in -source 1.5

I am confused - mven sees that I use java 8.

我很困惑 - mven 看到我使用 java 8。

pom.xml:

pom.xml:

<?xml version="1.0" encoding="UTF-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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>polyndrom</groupId>
    <artifactId>polyndrom</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.8.4</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.peterservice.polyndrom.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>           
        </plugins>
    </build>
</project>

采纳答案by mattweyant

By default, Maven assumes you wrote your code using JDK 1.5 and that you want to compile to that same target. You will need to add the maven-compiler-plugin to your build plugins, in order to tell it to use 1.8.

默认情况下,Maven 假定您使用 JDK 1.5 编写代码并且您希望编译到相同的目标。您需要将 maven-compiler-plugin 添加到您的构建插件中,以便告诉它使用 1.8。

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

Check out the plugin's docs for more info: http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

查看插件的文档了解更多信息:http: //maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

回答by talex

You can specify language version in properties

您可以在属性中指定语言版本

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

回答by Kamil Naja

I found possible solution for IntelliJ.

我找到了 IntelliJ 的可能解决方案。

Go into Project settings(ctrl + shift + alt + s). Then you can change language level into higher version.

进入项目设置(ctrl + shift + alt + s)。然后您可以将语言级别更改为更高版本。

enter image description here

在此处输入图片说明