文章目录
一、分模块开发与设计
二、聚合
当一个项目分割为多个maven项目后,如果其中一个模块进行了修改,重新install之后,其他的模块可能没有更新,就会导致项目出现问题,所以我们可以创建一个新的模块,对拆分的项目进行统一的管理
三、继承
<!-- 依赖声明 -->
<dependencyManagement>
<dependencies>
<!-- SpringBoot的依赖配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.5.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencyManagement>
四、属性
五、版本管理
六、资源配置
- 1、在pom文件中定义jdbc.url的属性
- 2、pom.xml配置资源文件对应的信息
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
- 3、在jdbc.properties中,使用${jdbc.url}替换值
七、多环境开发配置
- 1、在pom.xml中配置多环境
<profiles>
<profile>
<id>pro_env</id>
<properties>
<jdbc.url>jdbc:mysql://127.1.1.1:3306/ssm_db</jdbc.url>
</properties>
<activation>true</activation>
</profile>
<profile>
<id>dev_env</id>
<properties>
<jdbc.url>jdbc:mysql://127.2.2.2:3306/ssm_db</jdbc.url>
</properties>
</profile>
</profiles>
- 2、在打包的时候带上参数-P,如下图
八、跳过测试
- 1、跳过测试方式一:使用idea
- 2、跳过测试方式二:使用命令
如果右键没有run maven选项,可以去plugins中下载安装maven-helper
install -D skipTests
- 3、跳过测试方式三:使用配置的方式
<!-- 配置跳过测试 -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<!-- 设置跳过测试 -->
<skipTests>true</skipTests>
</configuration>
</plugin>
九、私服
我们使用nexus私服,下载地址:https://help.sonatype.com/repomanager3/product-information/download
1、进入我们的nexus网站,默认是:http://localhost:8081,点击右上角的登录
2、手动上传资源
创建一个宿主仓库
将新创建的宿主仓库放到maven-public仓库组中
将我们的依赖上传到hnzy-release仓库
3、idea环境中资源上传与下载
1、本地仓库配置访问私服
<servers>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->
<!-- 配置访问服务器的权限,用户名密码 -->
<server>
<!-- 自定义id -->
<id>hnzy-release</id>
<!-- 私服的用户名 -->
<username>admin</username>
<!-- 私服密码 -->
<password>walc1029</password>
</server>
<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
</servers>
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexus-aliyun</id>
<name>nexus-aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- 配置私服镜像 -->
<mirror>
<id>nexus-hnzy</id>
<name>nexus-hnzy</name>
<url>http://localhost:8081/repository/maven-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
2、如何配置发布到私服上
<!-- 发布配置管理 -->
<distributionManagement>
<!-- 正式版本发布仓库 -->
<repository>
<!--
对应setting.xml中的
<server>
<id>hnzy-release</id>
<username>admin</username>
<password>walc1029</password>
</server>
-->
<id>hnzy-release</id>
<!-- 要上传到的宿主仓库url -->
<url>http://localhost:8081/repository/hnzy-release/</url>
</repository>
<!-- 临时版本发布仓库 -->
<snapshotRepository>
<id>hnzy-snapshots</id>
<!-- 要上传到的宿主仓库url -->
<url>http://localhost:8081/repository/hnzy-snapshots/</url>
</snapshotRepository>
</distributionManagement>
3、配置好后,点击生命周期的deploy发布