Nexus 安装与使用

Nexus介绍

Nexus 是Maven仓库管理器,如果你使用Maven,你可以从Maven中央仓库 下载所需要的构件(artifact),但这通常不是一个好的做法,你应该在本地架设一个Maven仓库服务器,在代理远程仓库的同时维护本地仓库,以节省带宽和时间,Nexus就可以满足这样的需要。此外,他还提供了强大的仓库管理功能,构件搜索功能,它基于REST,友好的UI是一个extjs的REST客户端,它占用较少的内存,基于简单文件系统而非数据库。这些优点使其日趋成为最流行的Maven仓库管理器。除此之外,Nexus还可以管理Docker镜像

安装

我们使用 Docker 来安装和运行 Nexus,docker-compose.yml 配置如下:
1.创建目录
mkdir /usr/local/docker/nexus
2.进入nexus
cd nexus
3.创建docker-compose.yml
vi 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

保存退出

启动

docker-compose up -d

注: 启动时如果出现权限问题可以使用:chmod 777 /usr/local/docker/nexus/data 赋予数据卷目录可读可写的权限

登录控制台验证安装

地址:http://ip:port/ 用户名:admin 密码:admin123

在这里插入图片描述

使用

配置认证信息

在 Maven settings.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: 用于发布 Release 版本
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 中添加如下代码:

nexus-releases Nexus Release Repository http://127.0.0.1:8081/repository/maven-releases/ nexus-snapshots Nexus Snapshot Repository http://127.0.0.1:8081/repository/maven-snapshots/ 注意事项:

ID 名称必须要与 settings.xml 中 Servers 配置的 ID 名称保持一致。
项目版本号中有 SNAPSHOT 标识的,会发布到 Nexus Snapshots Repository, 否则发布到 Nexus Release Repository,并根据 ID 去匹配授权账号。

部署到仓库

mvn deploy

上传第三方 JAR 包

Nexus 3.0 不支持页面上传,可使用 maven 命令:

如第三方JAR包:aliyun-sdk-oss-2.2.3.jar

mvn deploy:deploy-file 
  -DgroupId=com.aliyun.oss 
  -DartifactId=aliyun-sdk-oss 
  -Dversion=2.2.3 
  -Dpackaging=jar 
  -Dfile=D:\aliyun-sdk-oss-2.2.3.jar 
  -Durl=http://127.0.0.1:8081/repository/maven-3rd/ 
  -DrepositoryId=nexus-releases

注意事项:

建议在上传第三方 JAR 包时,创建单独的第三方 JAR 包管理仓库,便于管理有维护。(maven-3rd)
-DrepositoryId=nexus-releases 对应的是 settings.xml 中 Servers 配置的 ID 名称。(授权)

配置代理仓库

<repositories>
    <repository>
        <id>nexus</id>
        <name>Nexus Repository</name>
        <url>http://127.0.0.1:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>nexus</id>
        <name>Nexus Plugin Repository</name>
        <url>http://127.0.0.1:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值