Maven——高级学习

一、分模块开发与设计

在这里插入图片描述

二、聚合

当一个项目分割为多个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发布

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值