0%

maven私服

maven私服

可以使用Nexus仓库管理器搭建maven私服,该页面默认用户和密码为admin/admin123

Nexus内置仓库

Nexus有四种类型的仓库:group(仓库组)、hosted(宿主)、proxy(代理)和virtual(虚拟)。

Nexus仓库类型

其流程为,Maven可以直接从宿主仓库下载构件;Maven也可以从代理仓库下载构件,而代理仓库会间接从远程仓库下载并缓存构件;为了方便,Maven可以从仓库组下载构件,而仓库组没有实际内容,会转向其包含的宿主仓库或者代理仓库获得实际构件的内容

其内置仓库为

  • Maven Central:该仓库代理maven中央仓库,策略为Release,只会下载和缓存中央仓库中的发布版本构件
  • Releases:策略为Release的宿主类型仓库,用来部署组织内部的发布版本构件
  • Snapshots:策略为Snapshot的宿主类型仓库,用来部署组织内部的快照版本构件
  • 3rd party:策略为Release的宿主类型仓库,用来部署无法从公共仓库获得的第三方发布版本构件
  • Apache Snapshots:策略为Snapshot的代理仓库,用来代理Apache Maven仓库的快照版本构件
  • Codehaus Snapshots:策略为Snapshot的代理仓库,用来代理Codehaus Maven仓库的快照版本构件
  • Google Code:策略为Release的代理仓库,用来代理Google Code Maven仓库的发布版本构件
  • java.net:策略为Release的代理仓库,用来代理jave net Maven仓库的发布版本构件
  • Public Repositories:该仓库将上述所有策略为Release的仓库聚合合并通过一致的地址提供服务
  • Public Snapshot Repositories:该仓库将上述所有策略为Snapshot的仓库聚合合并通过一致的地址提供服务

配置

download remote indexes 改为true

group组仓库 仓库的合集 按照配置的顺序找jar包
- proxy代理仓库1 ——url1 type为proxy
- proxy代理仓库2 ——url2
- hosted宿主仓库 mvn deploy会提交到hosted仓库中
- snapshot部署仓库
- release部署仓库
- 第三方jar包仓库 third party/3rd party

Virtual虚拟仓库,用于适配其他类型的仓库,比如maven要兼容maven1、maven2等

使用私服

想要使用私服时,需要在pom文件中配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<repositroies>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<!-- snapshots默认关闭的,需要手动开启 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

或者在settings中配置

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

<profiles>
<profile>
<id>nexus</id>
<repositroies>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<!-- snapshots默认关闭的,需要手动开启 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<!-- 需要激活对应的profile -->
<activeProfile>nexus</activeProfile>
</activeProfiles>

或者设置镜像

在settings.xml进行配置私服

1
2
3
4
5
6
7
<mirriors>
<mirror>
<id>nexus</id> 对应激活的profile
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url> 这个对应的是group组仓库的地址
</mirror>
</mirrors>

项目发布到私服

如果需要将项目发布到私服,需要在在pom文件中配置,发布工程时会用到,会发布到仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<distributionManagement>
<repository>
<!-- 要对应在nexus中的id -->
<id>releases</id>
<name>Nexus Releases</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<repository>
<!-- 要对应在nexus中的id -->
<id>snapshots</id>
<name>Nexus Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</repository>
</distributionManagement>

在发布时会使用到用户名,密码
此时应该在settings.xml中配置server

1
2
3
4
5
6
7
8
9
10
11
12
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123<password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123<password>
</server>
</servers>

私服权限管理

先设置权限 privileges
再设置角色 roles
再设置用户 users

欢迎关注我的其它发布渠道