前言

为什么要搭建私有仓库?一是学习新技术,二是方便自己制作相关组件或镜像上传私库并下载使用(后续用docker跑项目时需要用到私库上传镜像),大家时间都很宝贵,直接入正题吧

开始吧

下载Nexus windows版本安装包

Nexus Download

进去后会让填写基本信息,填写完成后就可以选择下载
在这里插入图片描述
由于国内网络问题,可能会下载不了,所以附上已下载好的百度网盘链接

链接:https://pan.baidu.com/s/1MlALcWn5IoMJh0Ff20MdXg?pwd=pdj8
提取码:pdj8

配置端口号

下载下来后解压,
打开 nexus-3.54.1-01-win64\nexus-3.54.1-01\etc\nexus-default.properties,修改端口号(不常用的 比如8888)
在这里插入图片描述

启动Nexus

保存后,进入nexus-3.54.1-01-win64\nexus-3.54.1-01\bin 目录,打开CMD命令框,执行nexus.exe

1
nexus.exe/run

后面等待系统启动Nexus
在这里插入图片描述
浏览器打开 http://localhost:8888(刚配置的端口号)
在这里插入图片描述

登录

点击右上角Sign in,会弹出提示,账号admin,初始密码在 nexus-3.54.1-01-win64\sonatype-work\nexus3\admin.password 文件中,拷贝输入确定后,会提示修改密码,一步一步执行完成即可。

配置Maven私库

因为Nexus里自带的有Maven仓库,所以不需要另外创建,只需要配置下Maven连接私库的地址即可
在这里插入图片描述

① 打开自己的Maven settings文件,配置Nexus私库地址(简单配置)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<mirrors>
<mirror>
<id>alimaven</id>
<!--central 代替中央仓库-->
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<servers>
<!-- 配置本地仓库访问私服的权限 nexus的 登录用户名密码 -->
<server>
<id>maven-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
<profiles>
<profile>
<id>nexus</id>
<!--远程仓库列表,它是Maven用来填充构建系统本地仓库所使用的一组远程项目。 -->
<repositories>
<repository>
<!--用于存储已经发布的Maven依赖包-->
<id>maven-releases</id>
<url>http://localhost:8888/repository/maven-releases/</url>
<!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<!--用于存储开发中的Maven依赖包-->
<id>maven-snapshots</id>
<url>http://localhost:8888/repository/maven-snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
<url>http://localhost:8088/repository/maven-public</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<!--激活私库配置-->
<activeProfiles>
<!--profile下的id-->
<activeProfile>nexus</activeProfile>
</activeProfiles>

② 上传公共组件至私库

  1. 手动打包上传
    在这里插入图片描述
    上传成功后就可以看到了
    在这里插入图片描述
  2. 配置项目pom,连接私库自动上传
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!-- 分发构件至远程仓库 -->
<distributionManagement>
<!--正式版本-->
<repository>
<!-- maven settings.xml中<server>的id-->
<id>maven-releases</id>
<name>nexus-releases</name>
<url>http://localhost:8888/repository/maven-releases/</url>
</repository>
<!--快照-->
<snapshotRepository>
<id>maven-snapshots</id>
<name>nexus-snapshots</name>
<url>http://localhost:8888/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>

idea打开maven构建,点击deploy
在这里插入图片描述
等待系统上传完成
在这里插入图片描述
回到nexus上可以看到刚上传的快照版本
在这里插入图片描述
如果要上传正式版本,只需要修改项目pom中项目的version版本,去掉SNAPSHOT后缀,重新deploy即可

1
2
3
4
5
<groupId>org.example</groupId>
<artifactId>download</artifactId>
<!-- 带SNAPSHOT为快照版本-->
<!--<version>1.0-SNAPSHOT</version>-->
<version>1.0</version>

在这里插入图片描述
这样就上传至正式库了,但是不管是快照还是正式的包,在maven-public中都是可以下载并引用的

在这里插入图片描述

③ 在其他项目中引用组件
在这里插入图片描述

配置项目pom

1
2
3
4
5
<dependency>
<groupId>org.example</groupId>
<artifactId>download</artifactId>
<version>1.0</version>
</dependency>

配置好后,Reload,maven会自动从上面配置的nexus私库中下载download组件

至此,简单的个人Maven私库就配置好了,是不是有手就行 ^ - ^。

最后

学如逆水行舟不进则退,要不断充实自己,不能让自己闲下来