前言
本文重要介绍了一下几个内容:
- linux中安装nexus,以及nexus中创建仓库,创建用户,创建角色,关联权限供实际项目中使用。
- 如何从多个远程仓库中下载jar包(即项目中jar包可能来自于多个仓库)。
- 如何将项目发布到nexus仓库。
nexus下载
nexus3基于jdk8,所以需要先安装jdk8环境。
推荐资源
nexus3下载官方网站:Download Archives - Repository Manager 3 (外网,很难下载下来)。
nexus3百度云盘下载:https://pan.baidu.com/s/1KzzpfA67En_nb59KQ7efEw(提取码:0000,nexus-3.25.1-04-unix.tar.gz)。
nexus安装
下载完成后,将安装包上传至linux服务器进行安装。
#创建安装目录
mkdir /home/software/nexus
#解压
tar -zxvf nexus-3.25.1-04-unix.tar.gz
解压出两个文件夹:nexus-3.25.1-04(用于实现 nexus 功能) 和 sonatype-work (用于存储数据)。
nexus常用命令
cd /home/software/nexus/nexus-3.25.1-04/bin
#后台启动服务
./nexus start
#停止服务
./nexus stop
#重启服务
./nexus restart
#查看服务状态
./nexus status
nexus默认端口为8081,服务根路径默认为/。如果需要变更可以更改nexus.properties配置。
#进入配置文件目录
cd /home/software/nexus/sonatype-work/nexus3/etc
#编辑配置文件
vim nexus.properties
nexus日志记录
#进入nexus日志记录目录
cd /home/software/nexus/sonatype-work/nexus3/log
nexus启动
后台启动nexus服务后,可通过http://xx:8081访问nexus web服务了。
#进入nexus bin目录
cd /home/software/nexus/nexus-3.25.1-04/bin
#后台启动nexus
./nexus start
nexus配置
nexus通常需要创建新的用户,给用户分配角色,角色关联相应权限。供项目中使用。
创建仓库
创建自定义仓库,项目发布时可将jar包发布到该仓库中。
关于仓库的类型说明:
项目 | 具体说明 |
---|---|
hosted | 本地存储。像官方仓库一样提供本地私库功能 |
proxy | 提供代理其它仓库的类型 |
group | 组类型,能够组合多个仓库为一个地址提供服务 |
点击创建仓库,创建好的仓库地址如下,项目发布时可引用该地址。
创建角色并分配权限
索引关键字:nx-repository-admin-maven2-
赋予仓库的权限,这里把maven2下 central、public、release、snapshots 库的非删除权限(如:browse、edit、read权限),都赋予给 新建的角色,另外把新建的私库的 * 权限(所有权限)也赋予给该角色。
检索自定义仓库的库名,赋予权限 nx-repository-view-maven2-自定义库名-*
检索 search、browse、upload 关键字,把 nx-search-read、nx-repository-view-*-*.browse、nx-comopnet-upload 权限赋予给该角色。这些权限用于展示如下菜单。
创建用户
nexus默认的账户名admin,初始密码在/home/software/nexus/sonatype-work/nexus3下的admin.password中,修改密码后该文件会消失。
创建新用户,并分配权限,后续项目中项目发布可使用该用户。
maven项目中使用nexus
公共服务项目经过验收测试无误时,可发布到私服供其他项目使用。
maven setting文件配置
<!--配置发布到私服某个仓库账户信息-->
<servers>
<server>
<id>test-repo</id>
<username>xx</username>
<password>xx</password>
</server>
</servers>
<!--此处指定多个mirrors镜像,镜像只会执行第一个位置mirror-->
<!-- <mirrors>
<mirror>
<id>devmaven</id>
<name>dev maven</name>
<url>http://xxx:xxxx/repository/xxx/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>-->
<!--从多个远程仓库下载jar包,查找次序为从下至上。即按照 aliyun->devmaven->maven中央仓库 顺序查询 -->
<profiles>
<profile>
<id>devmaven</id>
<repositories>
<repository>
<id>devmaven</id>
<url>http://xxx:xxxx/repository/xxx/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>aliyun</id>
<repositories>
<repository>
<id>aliyun</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<!--激活profile配置 -->
<activeProfiles>
<activeProfile>devmaven</activeProfile>
<activeProfile>aliyun</activeProfile>
</activeProfiles>
maven pom文件配置
<distributionManagement>
<repository>
<!--和setting中配置的id保持一致即可,不必和仓库名一致-->
<id>test-repo</id>
<name>common service</name>
<url>http://xxx:xxxx/repository/test-repo/</url>
</repository>
</distributionManagement>
执行mvn deploy命令完成项目发布。
参考:
Linux 部署 Nexus (下载、安装、使用)_Stephen·You的博客-CSDN博客_linux nexus
idea svn创建trunk主干、branch分支和tag标签_yy1209357299的博客-CSDN博客_svn 创建tag
Maven版本管理-Maven Release Plugin插件_和代码去流浪的博客-CSDN博客_maven 版本管理插件