- Nexus默认会带有四常用个仓库,maven-central、maven-public、maven-releases、maven-snapshots
- maven-central类型是proxy代理类型,地址是指向maven中央仓库地址https://repo1.maven.org/maven2/
- maven-releases、maven-snapshots类型是hosted宿主类型,即代表是上线的稳定版本依赖和开发阶段的快照版本
- maven-public类型是group组类型,里面是maven-releases、maven-snapshots、maven-central。即当指向maven-public时会去组下面的三个仓库去寻找包依赖
首先将我的Spring-Cloud工程里面的包依赖指向我搭建的nexus私服。首先修改maven的settings.xml。配置私服镜像
- servers配置虚拟机搭建的nexus私服默认的账号密码
mac-ubuntu admin admin123
- mirrors配置nexus私服镜像指向maven-public组
nexus central http://127.0.0.1:8081/repository/maven-public/
- 配置profile,由于我们镜像指向了maven-public仓库组,这里配置一个假地址
mac-nexus central http://central true true always warn central http://central true true always warn
- 配置activeProfiles,id是上面profile定义的id
mac-nexus
- 配置我的工程SpringCloud-Project中的parent-maven父类pom.xml,Github仓库。将配置打包至虚拟机nexus私服 id必须和maven setting.xml中server配置的ID一样(即mac-ubuntu),否则会找不到nexus私服报错401
mac-ubuntu Releases http://127.0.0.1:8081/repository/maven-releases/ mac-ubuntu Snapshot http://127.0.0.1:8081/repository/maven-snapshots/
- 执行mvn deploy打包项目,会看到依赖包会上传至maven-snapshots仓库。因为我pom.xml定义的是快照版本
由于我的SpringCloud-Project用的是springcloud。pom.xml文件中会使用spring-milestones这个仓库。这样我也需要将其配置至nexus私服
spring-milestones Spring Milestones https://repo.spring.io/milestone false
- 在nexus新建一个代理类型的仓库spring-m,地址指向https://repo.spring.io/milestone

- 在nexus新建一个group组类型的仓库spring-milestone,将上面新建好的spring-m仓库添加进来
[外链图片转存中…(img-VtS3oS8M-1669989739056)]
- 然后和上面配置maven-public一样,在maven的settings.xml中配置spring-milestone
nexus central http://127.0.0.1:8081/repository/spring-milestones/
spring-milestones spring-milestones https://spring true false spring-milestones https://spring true false
spring-milestones