nexus 私服仓库搭建
搭建目的
- 减少所有人都重复的从 Maven 远程仓库下载依赖组件时的仓库负载和外网带宽。
- 开发人员的协作,a部署a.jar的snapshot版本到镜像仓库,依赖方从私服仓库下载依赖a.jar的snapshot版本。上线后发布release版本
当被依赖方为snapshot版本时,mvn deploy时会自动发布到快照版本库中;依赖方即使本地仓库存在该快照版本模块1.0-SNAPSHOT,maven仍会自动从私服下载最新的快照版本。实际上被依赖方发布到快照仓库后,Version为1.0-发布时间
部分介绍
- 本地仓库
- 远程仓库
- 中央仓库 (是远程仓库中的一种)
host仓库—>内部项目的发布仓库
- Snapshots 发布内部snapshots版本的仓库
- Releases 发布内部release版本的仓库
- 3rd party 发布第3方jar包的仓库
docker 部署
docker pull sonatype/nexus3
mkdir –vp /home/nexus-data
// -v 前者为主机地址,后者为虚拟机地址
docker run -d --name nexus3 -p 8081:8081 -v /home/nexus-data:/var/nexus-data sonatype/nexus3
// 开放端口
firewall-cmd --permanent --add-port=8081/tcp
firewall-cmd --reload
// 查看密码
docker exec -it 550dd77a89e1 /bin/bash
vi /nexus-data/admin.password
exit
配置本地仓库的setting.xml,访问私服仓库
- 配置文件路径默认:${user.home}/.m2/
- 默认从中央仓库:https://repo.maven.apache.org/maven2/
- 配置访问私服server的用户名和密码(若私服不允许匿名访问)
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>123</password>
</server>
</servers>
- 配置profiles
<profiles>
<profile>
<id>profile-nexus</id>
<repositories>
<repository>
<id>nexus</id>
<url>http://192.168.136.200:8081/repository/maven-public/</url>
<snapshots><enabled>true</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://192.168.136.200:8081/repository/maven-public/</url>
<snapshots><enabled>true</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</pluginRepository>
</pluginRepositories>
</profile>
<!-- 激活私服镜像 -->
<activeProfiles>
<activeProfile>profile-nexus</activeProfile>
</activeProfiles>
配置私服仓库,提供服务给本地仓库
- 是否允许匿名访问
- 配置组 (排序)
- snapshots
- release
- aliyunProxy
- central
本地仓库部署snapshots到私服
- 配置server服务端的用户配置setting.xml
<server>
<id>deploy-release</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>deploy-snapshot</id>
<username>admin</username>
<password>admin123</password>
</server>
- 项目pom.xml的distributionManagement配置
<distributionManagement>
<repository>
<id>deploy-release</id>
<name>releases</name>
<url>http://192.168.136.200:8081/repository/maven-releases/</url>
<uniqueVersion>true</uniqueVersion>
</repository>
<snapshotRepository>
<id>deploy-snapshot</id>
<name>snapshots</name>
<url>http://192.168.136.200:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
- server的用户名和密码在nexus服务端的权限配置
nexus 3中,已经没有了能对maven私服进行deploy的默认用户,只有admin和匿名用户。为了让一个角色能够对maven进行deploy,需要向它添加nx-repository-view-maven2-*-edit的权限,同时给它匿名角色所有权限即可。
- nexus2版本中阿里云配置失效的问题
https://www.cnblogs.com/duanguyuan/p/11648584.html