Nexus安装配置教程

  • 格式:pdf
  • 大小:87.37 KB
  • 文档页数:1

Nexus安装配置教程

⽬录

为什么使⽤ Nexus

Nexus 最为⼤家熟知的功能就是 maven 的依赖包管理器。其实 Nexus 的功能不仅仅是 maven 的包管理,它还可以做 .net 包管理,docker 镜像管理,甚⾄还可以做 yum 源。这篇⽂章主要介绍 Nexus

的 maven 依赖管理功能,介绍 Nexus 的安装,配置。

架设 Nexus 私服有以下优点:

节省公司外⽹贷款;

因为依赖会被缓存到私服上,所以依赖的下载速度会很快;

⽅便上传团队内部的依赖,统⼀管理,共享。

Docker 模式安装 Nexus

我们选择使⽤ Docker 的⽅式安装 Nexus。

官⽅有两种⽅式

使⽤ docker 的 data volume (推荐)

使⽤本地⽬录作为 container 的 volume

使⽤ data volume

docker volume create --name nexus-data

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

使⽤本地⽬录

mkdir nexus

cd nexus

docker run -d -p 8081:8081 --name nexus -v $PWD/nexus-data:/nexus-data sonatype/nexus3

安装起来特别简单。安装完毕,访问 127.0.0.1:8081,可以直接登陆。

Nexus 配置

关于怎么配置 Nexus 这边不做太详细的说明。对默认的⼏个仓库坐下说明。

默认情况下,Nexus 会帮我们创建⼏个仓库:

maven-central:代理仓库,⼀般会连接外部的中央仓库;

maven-public:仓库组,⼀般提供这个仓库给公司内部的同事使⽤;

maven-release:本地仓库,⼀般⽤于存放公司内部开发的Jar包;

maven-snapshots:本地仓库,存放公司开发的snapshot版本的包;

maven-3rd-party:本地仓库,存放第三⽅的Jar包。

配置 Blob Stores

Nexus 使⽤

包下载

如果你只需要使⽤包下载功能,只需要替换本地的settings.xml即可。

D:\software\maven\Repository

nexus

devops

password

nexus

nexus

http://xx.xx.xx.xx:18081/repository/maven2-public/

nexus

nexus

http://nexus

true

true

nexus

http://nexus

true

true

nexus

包上传

⽅法⼀:通过 Nexus 界⾯上传给⽤户开通上传Jar包的权限。⽤户就可以通过页⾯上传Jar包了。

⽅法⼆:通过配置pom⽂件进⾏Jar包上传

在项⽬的pom中加⼊以下的配置。

nexus

nexus-snapshot

http://xx.xx.xx.xx:18081/repository/maven2-snapshots/

nexus

nexus-release

http://xx.xx.xx.xx:18081/repository/maven2-releases/

完成此步骤后,我们就可以通过执⾏mvn clean deploy进⾏发布了。Deploy插件会根据Maven项⽬中定义的version值决定是使⽤nexus-snapshot仓库还是nexus-release仓库。当version值是以-

SNAPSHOT后缀结尾时,则发布到nexus-snapshot仓库。

⽅法三:通过命令⾏(实质和上⾯pom的形式⼀样)

mvn deploy:deploy-file -DgroupId=com.jd.jr.xx -DartifactId=gateway-xx -Dversion=1.8.xx-SNAPSHOT -Dpackaging=jar -Dfile=xx-api-1.8.0-RELEASE.jar -Durl=http://124.205.xx.xx:18081/repository/maven2-snapshots/ -Drepos

上⾯的-DrepositoryId=nexus需要和配置的server标签匹配起来。

参考