什么是Nexus
Nexus是一个强大的仓库管理器, 极大地简化了内部仓库的维护和外部仓库的访问
2016年4月6日Nexus3.0版本发布, 相比较2.x有了很大的改变:
对底层代码进行了大规模重构, 提升性能, 增加可扩展性及改善用户体验
升级界面, 极大的简化了用户界面的操作和管理
提供新的安装包, 让部署更加简单
增加对Docker, NeGet, npm, Bower的支持
提供新的管理接口, 以及增强对自动任务的管理
基于Docker安装Nexus
使用Docker来安装和运行Nexus, docker-compose.yml配置如下:
version: '3.1'
services:
nexus:
restart: always
image: sonatype/nexus3
container_name: nexus
ports:
- 8081:8081
volumes:
- /usr/local/docker/nexus/data:/nexus-data
使用nexus3.0安装会遇到一个硬盘空间不够的问题, 可能是楼主机器比较弱, 即使给虚拟机20G的空间, 仍然会抛这个错误, 并且网上还没什么人遇到过这个错误, 于是退而安装2.x的版本
version: '3.1'
services:
nexus:
restart: always
image: sonatype/nexus
container_name: nexus
ports:
- 8081:8081
volumes:
- /usr/local/docker/nexus/data:/sonatype-work/
在安装过程中如果碰到权限的问题, 赋给data文件夹所有的权限即可
chmod 777 data/
登录控制台验证安装
用户名: admin
密码: admin123
在项目中使用Maven私服
配置认证信息
在Maven setting.xml中添加Nexus认证信息(servers节点下):
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
Snapshots与Releases的区别
nexus-releases: 用于发布Releases版本
nexus-snapshots: 用于发布Snapshot版本(快照版)
Release版本与Snapshot定于如下:
Release: 1.0.0/1.0.0-RELEASE
Snapshot: 1.0.0-SNAPSHOT
在项目pom.xml中设置的版本号添加SNAPSHOT标识的都会发布为SNAPSHOT版本, 没有SNAPSHOT标识的都会发布为RELEASE版本
SNAPSHOT版本会自动加一个事件作为标识, 如: 1.0.0-SNAPSHOT发布后变成1.0.0-SNAPSHOT-20180522.123456-1.jar
配置自动化部署
在pom.xml中添加如下代码:
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.25.143:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.25.143:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
注意事项:
ID名称必须要与setting.xml中Servers配置的ID名称保持一致。
项目版本中有SNAPSHOT标识的, 会发布到Nexus Snapshots Repository, 否则发布到Nexus Release Repository, 并根据ID区匹配授权账号。
部署到仓库
mvn deploy