Docker + Maven 搭建私有仓库

Docker + Maven 搭建私有仓库

1. 拉取镜像

docker pull nexus


2. 查看容器细节

docker inspect sonatype/nexus3:latest

  1. 查看镜像细节,以便挂载宿主机目录到容器目录。
  2. 查看暴露的端口号,以便宿主机映射。

看到 neuxs 数据文件目录在:/neuxs-data

3. 运行

docker run -d -p 8889:8081 -v /Users/Harry/workspace/.nexus-private-repository:/nexus-data sonatype/nexus3:latest

4. 初始化

  1. 点击右上角:Sign In
  2. 用户名 admin,密码在 /nexus-data/admin.password
  3. 登陆成功,继续。修改 admin 密码。
  4. 设置 -> Repositories -> maven-central -> 修改中央仓库为阿里云镜像仓库地址。
  5. 创建自己的 release,snapshots 仓库(可选,默认已有 release,snapshots 仓库)
  6. 创建角色,用户(可选)

5. 上传前配置

修改配置文件 settings.xml

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
<settings>
<!-- setp 1 -->
<servers>
<server>
<id>release</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>

<!-- setp 2 -->
<profiles>
<profile>
<id>demo</id>
<repositories>
<repository>
<id>release</id>
<url>http://localhost:8889/repository/maven-releases/</url>
</repository>
<repository>
<id>snapshots</id>
<url>http://localhost:8889/repository/maven-snapshots/</url>
</repository>
</repositories>
</profile>
</profiles>

<!-- setp 3 -->
<activeProfiles>
<activeProfile>demo</activeProfile>
</activeProfiles>
</settings>

6. 上传引用包

修改指定项目的 pom.xml

1
2
3
4
5
6
7
8
9
10
<distributionManagement>
<repository>
<id>release</id>
<url>http://localhost:8889/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8889/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>

上传成功

浏览页面

引用:

1
2
3
4
5
<dependency>
<groupId>xyz.yuzh.learning.springcloud.ribbon</groupId>
<artifactId>ribbon-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

使用阿里云 Maven 私有仓库服务

地址:https://repomanage.rdc.aliyun.com/my/repo?spm=a2c40.aliyun_maven_repo.repo_mvn_view.1.361865e9YU4Qdh

1). 开通云效(RDC)

2). 开启 私有仓库 服务

3). 配置 settings.xml

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
<settings>
<!-- **************** setp 1 **************** -->
<!-- 自己搭建的 -->
<server>
<id>release</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin</password>
</server>

<!-- RDC maven 服务 -->
<server>
<id>rdc-releases</id>
<username>tbnFB5</username>
<password>AiWt6eBk2r</password>
</server>
<server>
<id>rdc-snapshots</id>
<username>tbnFB5</username>
<password>AiWt6eBk2r</password>
</server>

<!-- **************** setp 2 **************** -->
<!-- 自己搭建的 -->
<profile>
<id>demo</id>
<repositories>
<repository>
<id>release</id>
<url>http://localhost:8889/repository/maven-releases/</url>
</repository>
<repository>
<id>snapshots</id>
<url>http://localhost:8889/repository/maven-snapshots/</url>
</repository>
</repositories>
</profile>

<!-- RDC maven 服务 -->
<profile>
<id>rdc-private-repo</id>
<repositories>
<repository>
<id>rdc-releases</id>
<url>https://repo.rdc.aliyun.com/repository/79540-release-xeyS8J/</url>
</repository>
<repository>
<id>rdc-snapshots</id>
<url>https://repo.rdc.aliyun.com/repository/79540-snapshot-eqA5Mg/</url>
</repository>
</repositories>
</profile>

<!-- **************** setp 3 **************** -->
<activeProfiles>
<activeProfile>demo</activeProfile>
<activeProfile>rdc-private-repo</activeProfile>
</activeProfiles>
</settings>

4). 修改 pom.xml

1
2
3
4
5
6
7
8
9
10
<distributionManagement>
<repository>
<id>rdc-releases</id>
<url>https://repo.rdc.aliyun.com/repository/79540-release-xeyS8J/</url>
</repository>
<snapshotRepository>
<id>rdc-snapshots</id>
<url>https://repo.rdc.aliyun.com/repository/79540-snapshot-eqA5Mg/</url>
</snapshotRepository>
</distributionManagement>

打包上传:mvn clean deploy -DskipTests

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×