5不支持lambda表达式

5不支持lambda表达式

本文介绍了行家。 -source 1.5不支持lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use maven to build my project.

我有以下配置:

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

but when I compile project I see following errors:

lambda expressions are not supported in -source 1.5

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

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

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>


推荐答案

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

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.

<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

这篇关于行家。 -source 1.5不支持lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:24