配置文件位置

找到自己Maven的本地安装位置,并找到配置文件

  • D:\devbasic\maven\apache-maven-3.6.0\conf

image.png

中央仓库

当建立一个Maven工程的时候,Maven会检查pom.xml中的依赖信息,并在本地仓库获得依赖资源,如果没有找到,然后会从默认中央仓库查找下载。

依赖搜索:https://mvnrepository.com/ 一般需要的Jar包依赖关系我们都可以在此网站中搜索到。

中央仓库分为两类:

  • 公共仓库:一些厂商提供的中央仓库地址(任何人都可以使用)
  • 私有仓库:企业或个人搭建的仓库地址(仅供内部使用)

全局配置-公共仓库

配置阿里云公共仓库,搜索 mirrors 在最上面添加以下内容

  1. <mirror>
  2. <id>nexus-aliyun</id>
  3. <mirrorOf>central</mirrorOf>
  4. <name>Nexus aliyun</name>
  5. <url>http://maven.aliyun.com/nexus/content/groups/public</url>
  6. </mirror>

image.png

全局配置-私有仓库

一般在企业开发中会有统一的私服地址,以企业、部门、项目组为单位的私服镜像仓库,用于内部制品的依赖获取与发布。

阿里云效Maven私服为例:点击进入

  1. 登录后需要新增一个企业
  2. 找到自己的私服仓库配置
  3. 按照流程进行配置

image.png

  • 在servers节点添加如下配置

    1. <servers>
    2. <server>
    3. <id>rdc-releases</id>
    4. <username>hfYti6</username>
    5. <password>******</password>
    6. </server>
    7. <server>
    8. <id>rdc-snapshots</id>
    9. <username>hfYti6</username>
    10. <password>******</password>
    11. </server>
    12. </servers>
  • 在profiles节点添加如下配置

    1. <profile>
    2. <id>rdc-private-repo</id>
    3. <repositories>
    4. <repository>
    5. <id>rdc-releases</id>
    6. <url>https://repo.rdc.aliyun.com/repository/70433-release-LlRIZy/</url>
    7. </repository>
    8. <repository>
    9. <id>rdc-snapshots</id>
    10. <url>https://repo.rdc.aliyun.com/repository/70433-snapshot-2vnfWJ/</url>
    11. </repository>
    12. </repositories>
    13. </profile>
  • 配置好了settings.xml后,在代码库根目录下的pom.xml加入以下配置:

    1. <distributionManagement>
    2. <repository>
    3. <id>rdc-releases</id>
    4. <url>https://repo.rdc.aliyun.com/repository/70433-release-LlRIZy/</url>
    5. </repository>
    6. <snapshotRepository>
    7. <id>rdc-snapshots</id>
    8. <url>https://repo.rdc.aliyun.com/repository/70433-snapshot-2vnfWJ/</url>
    9. </snapshotRepository>
    10. </distributionManagement>