maven compiler error -source 1.6 does not support lambda expressions

Copyright: personal essays, problems at work, only to save the document, hoping to help you, please correct me if wrong with progress! Thank you! https://blog.csdn.net/w893932747/article/details/90518725

Inscription:

       Pick up a new project, actually each update Idea compiled version will automatically change, finally get through the hard work! Share hereby

Error:

      maven update later version of Java compiler will automatically modify. As shown below: I only jdk1.8 local newspaper, but it turned out to be abnormal version 1.6, which is a bit of MMP.

the reason:

   Official statement:

Also note that at present the default source setting is 1.6 and the default target setting is 1.6, independently of the JDK you run Maven with. You are highly encouraged to change these defaults by setting source and target as described in Setting the -source and -target of the Java Compiler.

translation:     

目前默认的源设置为1.6,默认目标设置为1.6,与您运行Maven的JDK无关。 强烈建议您通过设置源代码和目标来更改这些默认值,如设置Java编译器的-source和-target中所述。

We ordinary people is: because the Maven Compiler plugin by default -source 1.6 and -target 1.6 add parameters to compile (estimate is for compatibility with some older Linux server operating system, they usually only JDK 6), and our code use the syntax of the JDK 7/8.

Solution:

Maven jdk modified version of the global or local configuration version jdk

First, the overall configuration jdk version (add the maven setting.xml file)

<profile>  
    <id>jdk17</id>  
    <activation>  
        <activeByDefault>true</activeByDefault>  
        <jdk>1.7</jdk>  
    </activation>  
    <properties>  
        <maven.compiler.source>1.8</maven.compiler.source>  
        <maven.compiler.target>1.8</maven.compiler.target>  
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>  
    </properties>   
</profile>

Second, the configuration of the local version of jdk (jdk version configuration information in the project)

<project>
...
<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>
</project>

OK, problem solved!

Guess you like

Origin blog.csdn.net/w893932747/article/details/90518725