在 部署 Nexus 私服 这篇文章中配置了 Nexus 的服务端,接下来要配置一下本地 maven 如何连接 Nexus 服务端使用。
1、首先打开我们本地 maven 的配置文件

2、一般情况下我们会修改本地仓库位置

3、配置镜像仓库
<mirrors> 元素
<server> 中的 id 匹配central(只有通过中央仓库下载的依赖才会从私服下载) 或 * (所有依赖均通过私服下载)<mirrors>
<mirror>
<id>nexus-public</id>
<mirrorOf>*</mirrorOf>
<name>Nexus Public</name>
<url>http://192.168.228.18:8081/repository/maven-public/</url>
</mirror>
</mirrors>
如果 Nexus 服务端没有 开启匿名访问 的话,需要在 <server> 元素配置对应的访问认证信息,id 要与上面 mirror 中的 id 对应
<servers>
<server>
<id>nexus-public</id>
<username>admin</username>
<password>123456</password>
</server>
</servers>
4、通过 mvn deploy 命令推送 jar 包到私服
<server> 访问认证信息<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>123456</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>123456</password>
</server>
</servers>
pom.xml 文件,这里的 id 要与上面 server 中的 id 对应<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.228.18:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.228.18:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
pom.xml<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
<localRepository>D:\repo</localRepository>
<servers>
<server>
<id>nexus-public</id>
<username>admin</username>
<password>123456</password>
</server>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>123456</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>123456</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-public</id>
<mirrorOf>*</mirrorOf>
<name>Nexus Public</name>
<url>http://192.168.228.18:8081/repository/maven-public/</url>
</mirror>
</mirrors>
</settings>
在 部署 Nexus 服务端 ,配置仓库的时候,我们知道 Nexus 不仅可以作为 maven 的私服,还可以作为 docker、apt、npm 等依赖管理工具的私服,这里我们配置一下 npm 私服仓库

1、配置代理仓库,代理淘宝镜像源
npm(proxy)
npm-taobaohttps://registry.npm.taobao.org2、配置私有仓库
npm(hosted)
npm-hosted3、配置分组仓库
npm(group)
npm-publicnpm-taobao 和 npm-hosted