前言
通过Sonetype的nexus创建Maven私服
准备工作
基本命令
安装服务
1
| nexus/bin/excus.exe /install
|
卸载服务
1
| nexus/bin/excus.exe /uninstall
|
前台运行
1
| nexus/bin/excus.exe /run
|
后台运行
1
| nexus/bin/excus.exe /start
|
后台退出
1
| nexus/bin/excus.exe /stop
|
查看运行状态
1
| nexus/bin/excus.exe /status
|
登陆控制台
初始密码
Username:admin
Password:在nexus/sonatype-work/nexus3/admin.password
中存储
私服仓库的分类
类别 |
名称 |
功能 |
操作 |
宿主仓库 |
hosted |
保存自主研发和第三方依赖 |
上传 |
代理仓库 |
proxy |
代理连接中央仓库 |
下载 |
仓库组 |
group |
为仓库编组,简化下载操作 |
下载 |
配置私服从远端同步
- 修改
maven-central
的Remote storage
配置,改为其他远端仓库,例如阿里仓库:`
修改私服配置
修改端口号
nexus/sonatype-work/nexus3/etc/nexus.properties
修改本地Maven配置
配置连接私服中仓库的权限
- 创建类型为
maven2(hosted)
,名称为domain-release
的仓库
- 创建类型为
maven2(hosted)
,名称为domain-snapshot
的仓库
<id></id>
:指定hosted类型的仓库名称
<username></username>
:配置连接私服用户名
<password></password>
:配置连接私服密码
maven/conf/settings.xml1 2 3 4 5 6 7 8 9 10 11 12
| <servers> <server> <id>domain-release</id> <username></username> <password></password> </server> <server> <id>domain-snapshot</id> <username></username> <password></password> </server> </servers>
|
配置连接私服地址
<id></id>
:指定group类型的仓库名称
<mirrorOf></mirrorOf>
:指定哪些依赖从私服中的仓库获取
<url></url>
:指定仓库URL
maven/conf/settings.xml1 2 3 4 5 6 7
| <mirrors> <mirror> <id></id> <mirrorOf>*</mirrorOf> <url></url> </mirror> </mirrors>
|
修改项目pom.xml配置
<repository></repository>
:发布到正式版
<snapshotRepository></snapshotRepository>
:发布到快照版
<id></id>
:指定hosted类型的仓库名
<url></url>
:指定仓库URL
pom.xml1 2 3 4 5 6 7 8 9 10
| <distributionManagement> <repository> <id></id> <url></url> </repository> <snapshotRepository> <id></id> <url></url> </snapshotRepository> </distributionManagement>
|
上传到私服
- 通过Maven的deploy生命周期,将项目发布到私服
根据项目版本号的后缀,自动发布到指定版本的仓库。如果是x-x-RELEASE
则发布到domain-release仓库;如果是x-x-SNAPSHOT
则发布到domain-snapshot仓库
完成
参考文献
哔哩哔哩——黑马程序员
CSDN——野猿新一