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

问题描述

我使用 maven 构建我的项目.

I use maven to build my project.

我有以下配置:

D:freelancepolyndrom>mvn -verion Apache Maven 3.2.3(33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T00:58:1 0+04:00)Maven 主目录:C:Program Filesapacheapache-maven-3.2.3 Java 版本:1.8.0_25,供应商:Oracle Corporation Java 主页:C:Program FilesJavajdk1.8.0_25jre 默认语言环境:ru_RU,平台编码:Cp1251 操作系统名称:windows 7",版本:6.1",arch:amd64",系列:做"

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

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>

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

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