Maven配置文件配置指定JDK版本
方法一:全局指定 settings.xml(第20行)
1 <!-- 指定本地仓库位置 --> 2 <localRepository>D:\repository\</localRepository> 3 4 <!-- 指定远程镜像 --> 5 <mirrors> 6 <mirror> 7 <id>central</id> 8 <mirrorOf>central</mirrorOf> 9 <name>aliyunmaven</name> 10 <url>https://maven.aliyun.com/repository/central</url> 11 </mirror> 12 <mirror> 13 <id>apache.snapshots.https</id> 14 <mirrorOf>apache.snapshots.https</mirrorOf> 15 <name>aliyunmaven</name> 16 <url>https://maven.aliyun.com/repository/apache-snapshots</url> 17 </mirror> 18 </mirrors> 19 20 <!--指定JDK等参数--> 21 <profiles> 22 <profile> 23 <id>jdk-1.8</id> 24 <activation> 25 <jdk>1.8</jdk> 26 <activeByDefault>true</activeByDefault> 27 </activation> 28 <properties> 29 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 30 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 31 <maven.compiler.encoding>UTF-8</maven.compiler.encoding> 32 <maven.compiler.source>1.8</maven.compiler.source> 33 <maven.compiler.target>1.8</maven.compiler.target> 34 <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> 35 </properties> 36 </profile> 37 </profiles>
方法二:当前项目 pom.xml中指定(第28行)
1 <properties> 2 <java.version>11</java.version> 3 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 4 </properties> 5 6 <repositories> 7 <repository> 8 <id>public</id> 9 <url>https://maven.aliyun.com/repository/public</url> 10 <snapshots> 11 <enabled>false</enabled> 12 </snapshots> 13 </repository> 14 </repositories> 15 16 <pluginRepositories> 17 <pluginRepository> 18 <id>public</id> 19 <url>https://maven.aliyun.com/repository/public</url> 20 <snapshots> 21 <enabled>false</enabled> 22 </snapshots> 23 </pluginRepository> 24 </pluginRepositories> 25 26 <build> 27 <plugins> 28 <!-- 指定jdk --> 29 <plugin> 30 <groupId>org.apache.maven.plugins</groupId> 31 <artifactId>maven-compiler-plugin</artifactId> 32 <version>3.8.1</version> 33 <configuration> 34 <skip>true</skip> 35 <source>${java.version}</source> 36 <target>${java.version}</target> 37 <encoding>${project.build.sourceEncoding}</encoding> 38 </configuration> 39 </plugin> 40 <!-- 跳过测试 --> 41 <plugin> 42 <groupId>org.apache.maven.plugins</groupId> 43 <artifactId>maven-surefire-plugin</artifactId> 44 <version>3.0.0-M4</version> 45 <configuration> 46 <skip>true</skip> 47 <skipTests>true</skipTests> 48 </configuration> 49 </plugin> 50 </plugins> 51 </build>