Step 1、准备工作
1.1、安装jdk1.8 https://blog.csdn.net/tmaczt/article/details/83347293
1.2、安装Maven3.x https://blog.csdn.net/tmaczt/article/details/119924285
1.3、下载源码:https://github.com/sonatype/nexus-public/releases/tag/release-3.33.1-01
Step 2、编译项目
2.1 修改rebulid.bat
2.2、执行编译命令
mvnw.cmd -Dmaven.test.skip=true
注意:第一次编译时间较长大概1个小时左右,项目比较多需要下载的jar很多。如有错误请根据错误提示找解决办法。
Step 3、复制编译后的可执行文件
相对路径为:assemblies\nexus-base-template\target
Step 4、启动服务
- 解压zip文件:unzip nexus-base-template-3.33.0-01.zip
- 切换到bin目录:cd /opt/soft/nexus-base-template-3.33.0-01/bin
- 修改web端口:vim …/etc/nexus-default.properties
4.启动服务:./nexus start
Step 5、访问web站点设置配置仓库
5.1 设置账号信息:
浏览器打开:http://localhost:8091/
使用admin登录,默认密码在服务端目标下有个密码文件。没有的话使用admin123登录,我本地是admin123.
5.2 登录后切换到设置页面:
5.2.1 新建repository :
repository三种类型:
group:是一个仓库组,可包含hosted和proxy两种库,下载时按配置顺序从中依次查找
hosted:一般部署我们自己项目打包的jar
proxy:代理远程仓库,maven-central是默认maven中央仓库代理,aliyun是后加的阿里远程库代理,通过代理从远程库中下载的依赖都会被缓存到nexus的proxy库中
proxy类型的repository:代理一些远程仓库
hosted类型repository
Release仓库:存放release版本,设置为不可重复发布(稳定)。
Version Policy:Release ,Deployment policy:Disable redeploy
Snapshot仓库:存放Snapshot版本,可重复发布(不稳定)。
Version Policy:Snapshot ,Deployment policy:Allow redeploy
group类型repository:将一些仓库组合到一起提供给客户端使用。
5.2.2 repositories状态查看
6、nexus私服在项目中使用
6.1、更新maven镜像,修改maven_hone/conf/settings.xml
6.2、idea设置maven环境
6.3、pom文件中增加发布设置
6.4、配置source-plugin插件生成source.jar
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
7、浏览仓库中Repository
总结:完成以上操作,单机版的nexus私服基本搭建完成。