四、属性
4.1 使用属性
一般在聚合工程中,在properties标签下以标签形式自定义属性,使用属性可以解决多个版本号一致时修改不方便的问题,将版本号定义成变量引用。
<properties>
<!-- 一个pom文件中只能有一个properties标签-->
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<!-- 定义属性(用于替换版本号这些信息)-->
<spring.webmvc>5.2.10.RELEASE</spring.webmvc>
</properties>
子工程使用属性
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.webmvc}</version>
</dependency>
4.2 配置文件加载属性
4.3 版本管理
工程版本 | 发布版本 |
包括SNAPSHOT快照版本和RELEASE发行版本。 | 包括alpha,纯数字和beta版本。 |

五、多环境开发和跳过测试
5.1 多环境开发

(1)使用profiles标签定义多个不同的环境并设置默认环境
<!-- 模拟定义多环境-->
<profiles>
<profile>
<!-- 开发环境-->
<id>env_dep</id>
<properties>
<!-- 属性-->
<jdbc.url>jdbc:mysql://localhost:3306/test</jdbc.url>
</properties>
</profile>
<profile>
<!-- 生产环境-->
<id>env_pro</id>
<properties>
<jdbc.url>jdbc:mysql://127.1.1.1:3306/test</jdbc.url>
</properties>
<!-- 设置这个环境是默认环境-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- 测试环境-->
<id>env_test</id>
<properties>
<jdbc.url>jdbc:mysql://127.3.3.2:3306/test</jdbc.url>
</properties>
</profile>
</profiles>
(2)使用命令选择执行环境


5.2 跳过测试
(1)跳过全部测试
使用maven工具:

点击图中的闪电按钮之后,执行maven指令即可跳过测试。
使用mvn命令:

在pom文件中配置测试插件:
<plugins>
<!-- 配置测试插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<!-- 是否跳过测试:是-->
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
(2)跳过一部分不测试
<plugins>
<!-- 配置测试插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<!-- 是否跳过测试:否-->
<skipTests>true</skipTests>
<!-- 排除这个类,不测试-->
<excludes>**/BookServiceImplTest.java</excludes>
</configuration>
</plugin>
</plugins>
六、私服
6.1 私服简介和安装
1.私服是什么
私服是一个特殊的远程仓库,它是架构在局域网内的仓库服务,供局域网内的开发人员使用。当Maven需要下载构建的使用,它先从私服请求,如果私服没有的话,则从外部的远程仓库下载,然后缓存在私服上,再为Maven的下载请求提供服务。


2.私服的作用
- 内网访问,节省外网带宽。
- 一次外网下载,内网所有用户就可以只下载私服缓存,加速Maven项目构建。
- 不被外部访问,更加安全。
- 减少外部网络因素,更加稳定。
- 方便内部项目服务的依赖引用,而不需要其他项目的完整源代码。
3.Nexus下载使用
Nexus是一个仓库管理器,通过Nexus来搭建Maven的私服。
步骤:
(1)下载私服

(2)启动Nexus并使用浏览器访问





修改端口,默认端口是8081


6.2 私服仓库

6.3 本地仓库配置私服
(1)在Nexus存储管理器上新建两个maven仓库,并加入到maven-public仓库组中。






6.4 私服资源上传和下载
<!-- 如果是发行版本,版本要改为RELEASE,如果是快照版,就写Snapshot-->
<groupId>org.example</groupId>
<artifactId>maven_4</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- 上传项目到私服-->
<distributionManagement>
<!-- 上传为发行版-->
<repository>
<id>itxiaoguo-release</id>
<url>http://localhost:8081/repository/itxiaoguo-release/</url>
</repository>
<!-- 上传为快照版-->
<snapshotRepository>
<id>itxiaoguo-Snapshot</id>
<url>http://localhost:8081/repository/itxiaoguo-Snapshot/</url>
</snapshotRepository>
<!-- 如果要同时发布,要修改版本-->
</distributionManagement>