简体   繁体   English

使用Java 9编译Lambda表达式时Maven构建失败

[英]Maven build failure at compilation for lambda expression using java 9

I am building a sample for maven spring boot, using java 9, getting compilation error while doing clean package using maven build plugin. 我正在使用Java 9构建Maven Spring Boot的示例,使用Maven构建插件进行干净的打包时会出现编译错误。

  • java build path : selected JRE 9 Java构建路径:选定的JRE 9
  • Java compiler : Enabled Project specific settings (selected as 9) Java编译器:已启用项目特定设置(选择为9)
  • Eclipse preferences : Java -> Installed JRE -> Selected JRE 9 Eclipse首选项:Java->已安装的JRE->选定的JRE 9
  • Run Configuration : Workplace default JRE (selected java 9) 运行配置:工作场所默认JRE(已选择Java 9)

Don't know from where maven is picking 1.6 不知道Maven从哪里选1.6

pom.xml 的pom.xml

<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>com.jaggs.springboot</groupId>
    <artifactId>HelloSpringBoot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>HelloSpringBoot</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.ersion>1.9</java.ersion>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <source>1.9</source>
                    <target>1.9</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

构建错误日志

Since you don't specify the maven-compiler-plugin explicitly, it's definition is taken from your project's parent's, spring-boot-starter-parent . 由于您没有明确指定maven-compiler-plugin ,因此它的定义取自您项目的父级的spring-boot-starter-parent

The maven-compiler-plugin's version there is defined by the ${java.version} property which you've attempted to override, but unfortunately had a typo - you set java.ersion instead of java.version (note the missing v ). maven-compiler-plugin的版本由您尝试覆盖的${java.version}属性定义,但不幸的是有错字-您设置了java.ersion而不是java.version (请注意缺少的v )。 Thus, the plugin's default of 1.6 is used. 因此,将使用插件的默认值1.6。 Just fix the typo, and you should be fine: 只需修正拼写错误,就可以了:

<java.version>1.9</java.version>
<!-- -^-----------------^ -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM