Set the JDK compiled version of the maven project (take JDK 1.8 as an example)

Set the JDK compiled version of the maven project (take JDK 1.8 as an example)

1. Enter the global configuration in maven setting.xml

<!-- 全部 maven 项目默认使用 jdk1.8构建 -->
<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>   
  <repositories>
    <repository>
      <id>jdk18</id>
      <name>Repository for JDK 1.8 builds</name>
      <url>http://www.myhost.com/maven/jdk18</url>
      <layout>default</layout>
      <snapshotPolicy>always</snapshotPolicy>
    </repository>
  </repositories>
</profile>

2. Enter the plugin configuration in the project's pom.xml

<!-- 使用Java8构建项目 -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <testSource>1.8</testSource>
        <testTarget>1.8</testTarget>
    </configuration>
</plugin>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324610116&siteId=291194637