maven 私服nexus的使用

源码安装方式搭建

因nexus比较消耗资源,linux环境需要提供至少2G以上内存

1、下载源码包

https://www.sonatype.com/download-oss-sonatype下选择unix版本

或者到peter的云盘(https://pan.baidu.com/s/1OjuyfgdIgR49rwnrzC-J5g 提取码:ax7t )

2、解压

tar -zxvf nexus-3.15.2-01-unix.tar.gz  -C  nexus

3、设置用户并启动

maven 私服nexus的使用

maven 私服nexus的使用

docker方式安装

1、创建一个持久目录,存放nexus数据

mkdir  /nexus-data

chown  200 /nexus-data   ##此处200对应容器内nexus用户的id

2、docker命令直接启动(网速慢的建议先docker pull sonatype/nexus3)

docker run -d --name nexus --privileged=true  -p 8081:8081 -v /nexus-data:/nexus-data sonatype/nexus3

maven 私服nexus的使用

nexus概念与使用

登陆

打开nexus地址如:http://192.168.244.6:8081/

使用admin/admin123登陆

maven 私服nexus的使用

搜索

maven 私服nexus的使用

Nexus的仓库类型

maven 私服nexus的使用

group(仓库组类型--门面):组合自己的多个库,成为一个路径对外提供服务;
hosted(宿主类型):内部项目的发布仓库,内部jar存在在这;
proxy(代理类型):代理一个远程仓库url,缓存一份打此经过的jar

nuget库是 NET库

配置国内代理加速

--------因maven*仓库速度慢,我们一般优先使用国内远程仓库,这里配一个aliyun代理

点击create repository按钮,填写name与remote storage值

maven 私服nexus的使用

调配nexus对外的门面

------------当外部请求nexus下载jar时,nexus统一对外部提供一个服务窗口。我们配置它对远程仓库的代理顺序。

 

编辑maven-public库,加入aliyum远程仓库

maven 私服nexus的使用

当查询构件时,会依次查releases/napshots/aliyun/central这四个库:

优先级:本地最优先,aliyun次之,central最末(因其速度最慢)

使用nexus拉取jar包

我们的nexus对外服务地址url,如下图

maven 私服nexus的使用

配置此url有两种方式:

1、全局配置方式

在maven的setting文件里,通过mirror指定私服地址,此方式对全局生效

maven 私服nexus的使用

2、局部配置方式

在本项目的pom里,指定repository配置,此方式只对本项目生效

maven 私服nexus的使用

上传jar到nexus

1、手动上传

直接在nexus的界面上,使用upload上传

maven 私服nexus的使用

填写jar与坐标

maven 私服nexus的使用

在browse界面里,可查到上传的jar

maven 私服nexus的使用

2、命令上传

命令方式上传,需要权限认证,在setting文件中配置

maven 私服nexus的使用

在项目pom中,配置上传url

maven 私服nexus的使用

mvn  deploy命令直接上传

maven 私服nexus的使用

maven 私服nexus的使用

设置允许覆盖发布

maven 私服nexus的使用