SpringBoot启用Java预览版特性(无测试类)
在pom.xml
文件中加入以下配置表示启用Java
预览版
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${java.version}</release>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
当项目中包含此配置,若无SpringBootTest
测试类,则能正常编译打包
SpringBoot启用Java预览版特性(含测试类)
若项目中包含单元测试则需要额外配置--enable-preview
参数
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${java.version}</release>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
Maven package与单元测试的关系
Maven执行package前会执行一次test
由于spring-boot-starter-test
依赖的作用域是test,SpringBootTest
的单元测试类不会参与打包
但若是单元测试不通过,则会导致打包失败