Transfer, thanks to the author's selfless sharing.
problem:
- Create a project when maven, jdk version is version 1.7, and version 1.8 is installed themselves, making it impossible to use Java8 new features such as lambda.
- Every Right project name -maven-> update project when the project will change back to jdk version 1.7 version.
Solution:
Solution one: specify jdk version in the project pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
This method can only guarantee that the project is jdk1.8 version, each new project had to add the above code, is not recommended, recommended the second approach.
Solution two: find maven settings.xml file in the installation directory, and add the following code inside
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</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>
Note: the low version of Maven might not recognize high version of the JDK.