文章目录
1. Maven私有仓库安装
1.1 本机配置
- Windows 10 x64
1.2 官网下载地址
我这里下载的是Windows的版本
1.3 解压
解压得到两个文件夹
- nexus-3.30.1-01
- sonatype-work
1.4 启动
进到 nexus-3.30.1-01/bin
目录下,使用cmd窗口执行命令:nexus.exe /run
看到下面的日志时,启动完成:
1.5 登陆界面
默认登陆页面地址:http://localhost:8081
1.5.1 登陆
点击右上角的 Sign in
,会提示你对应的账号密码是什么,如下图
- 第一次登录后会提醒你换admin账号的密码,我这里设置成admin/admin
- 记得勾选Allow anonymous users to access the server
1.5.2 更改端口号
此端口可在 sonatype-work\nexus3\etc\nexus.propertis
文件里更改
至此,nexus3就安装完成了
2. 搭建
2.1 主要Type介绍
- group:
- Public Repositories,仓库组
- hosted:
- 3rd party:无法从公共仓库获得的第三方发布版本的构件仓库,比如oracle jar包等(版权保护无法从官网免费下载)
- Snapshot:用于存放快照版本(Snapshots)的仓库
- Releases:用于存放稳定版本的jar和war或者插件的仓库
- proxy:
- Central:用来代理maven中央仓库中发布版本构件的仓库
- Apache Snapshots:用了代理ApacheMaven仓库快照版本的构件仓库
后面创建测试组件的时候,会进一步了解到它们的作用
2.2 创建物理存储库
-
进到管理界面,可以看到默认已经有一个名为default的存储库
-
填写必要条件,点击
Create blob store
即可
2.3 创建Proxy
现在我们的私有仓库是空的,设置我们的proxy连向阿里云仓库地址。当在私有仓库中拿不到对应的jar包,则会去proxy对应的仓库拉取jar包。
2.4 创建hosted
用于:当我们要将本地jar包通过maven命令上传到私有库,我们这里会创建两个hosted:Release + Snapshot。
2.4.1 release hosted
2.4.2 snapshot hosted
2.5 创建group
2.6 创建用户
2.7 小结
至此,目前我们需要的都创建完了,结果如图:
3. 使用
3.1 项目目录介绍
我们有两个模块:
- ModuleA:
- 用于演示拉取阿里云仓库的依赖;
- 用于演示上传ModuleA的jar包到我们的私有库中;
- ModuleB
- 用于演示从私有库中拉取ModuleA的jar包下来;
3.2 拉取阿里云仓库的依赖
3.2.1 修改settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"