多环境配置与应用
1. 多环境配置作用
- maven提供配置多种环境的设定,帮助开发者使用过程中快速切换环境

2. 多环境配置步骤
2.1 定义多环境
xml
<!--定义多环境-->
<profiles>
<!--定义具体的环境:生产环境-->
<profile>
<!--定义环境对应的唯一名称-->
<id>env_dep</id>
<!--定义环境中专用的属性值-->
<properties>
<jdbc.url>jdbc:mysql://127.0.0.1:3306/ssm_db</jdbc.url>
</properties>
<!--设置默认启动-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!--定义具体的环境:开发环境-->
<profile>
<id>env_pro</id>
......
</profile>
</profiles>
若不了解资源文件引用属性的可以参考上一篇文章Maven之属性管理
2.2 使用多环境(构建过程)
cmd
【命令】:
mvn 指令 --P 环境定义id
【范例】:
mvn install --P pro_env
2. 跳过测试(了解)
2.1 应用场景
- 功能更新中并且没有开发完毕
- 快速打包
- ......
2.2 跳过测试命令
- mvn install --D skipTests
如果是在idea中,点击Toggle 'Skip Tests'Mode,即可跳过测试


注意事项:
- 执行的项目构建指令必须包含测试生命周期,否则无效果。例如执行compile生命周期,不经过test生命周期。执行install生命周期,经过test生命周期
2.3 细粒度控制跳过测试
配置插件
xml
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<!--设置跳过测试-->
<skipTests>true</skipTests>
<!--要想精准控制,配置-->
<includes>
<!--包含指定的测试用例-->
<include>**/User*Test.java</include>
</includes>
<excludes>
<!--排除指定的测试用例-->
<exclude>**/User*TestCase.java</exclude>
</excludes>
</configuration>
</plugin>