Nexus Repositories 介绍

1 Repositories介绍
在Nexus的Repositories中,主要有两种类型的工厂hosted和proxy
hosted本地工厂:只是面向内部服务的,面向局域网
3rd party :存放Maven中央仓库中没有的第三方jar包
Releases  :存放Maven中提交的Releases项目
Snapshots :存放Maven中提交的Snaphots项目
proxy代理工厂:
Central:存放从Maven中央工厂中下载下来的jar包
例如:Central中需要配置Maven中央工厂的地址
Apache Snapshots:存放专门从Apache下载的Snapshots的jar包
Codehaus Snapshots:存放专门从Codehaus下载的Snapshots的jar包


2 Maven中配置Nexus Repositories
配置Maven不从Maven自身的中央工厂找jar包,而是从这个Nexus私服工厂中找jar包
临时配置(用户配置):表示只针对当前项目的配置方式,只要当前项目找jar包的时候是来Nexus中找,但是如果再有一个新项目。就还是从Maven中来下载jar包了
打开pom.xml添加配置

1
2
3
4
5
6
7
< repositories >
      < repository >
          < id >nexus</ id >
          < name >Nexus Repository</ name >
          < url >http://localhost:8081/nexus/content/groups/public/</ url >
      </ repository >
</ repositories >

其中url的值,就是Public repositories的URL值


全局配置:这样配置表示不管哪个项目,只要局域网内使用Maven下载jar包,都会来Nexus的私服工厂中来下载。
通过修改Maven的setting.xml的全局配置文件
增加一个或者多个profile配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
< profiles >
     < profile >
         < id >nexusProfile</ id >
         < repositories >
           < repository >
             < id >nexus</ id >
             < name >Nexus Repository</ name >
             < url >http://localhost:8081/nexus/content/groups/public/</ url >
             <!-- releases默认是true -->
             < releases >< enabled >true</ enabled ></ releases >
             <!-- snapshots默认是false -->
             < snapshots >< enabled >true</ enabled ></ snapshots >
           </ repository >
         </ repositories >
       </ profile >
</ profiles >
< activeProfiles >
     <!-- 激活nexusRepo这个profile:只有激活才生效 -->
     < activeProfile >nexusProfile</ activeProfile >
</ activeProfiles >

3 配置Nexus的镜像
配置Nexus的镜像的目的是:有时候我们每个开发人员需要在我们的私服中找jar包,但是如果私服中也没有的话,就会去Maven的中央工厂中找。可能会有这样的需求,就是你们开发人员不允许直接去中央工厂找jar包,你们所需要的jar包都来我们内部的私服来找。如果私服里也找不到,那就是找不到了【通知项目经理需要\*\*.jar包】
同样是在Maven的全局配置文件settings.xml中配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
< mirrors >
< mirror >
   < id >nexusMirror</ id >
   <!-- 配置工厂镜像,只要mirror中配置的工厂需要找jar包,都来这个url中找[也就是都来私服中找]
   即使在这个私服中找不到了,也不会去Maven的中央工厂中找
   mirrorOf中配置的表示是工厂的id
   central工厂位置:apache-maven-3.3.9\lib\maven-model-builder-3.3.9.jar\pom-4.0.0.xml
   central工厂表示是Maven自己的工厂https://repo.maven.apache.org/
   maven2,这个地址就是Maven默认去找jar包的一个Maven中央工厂
    -->
   
   <!-- 这里也可以使用*号来代替所有的工厂都使用这个镜像来获取jar包
   <mirrorOf>nexus,central</mirrorOf>
   -->
   < mirrorOf >*</ mirrorOf >
   < name >Human Readable Name for this Mirror.</ name >
</ mirror >
</ mirrors >

当然,如果这里定义mirror,那上面定义的激活profile的定义就没什么意义了,可以直接注释掉

1
2
3
4
< activeProfiles >
     <!-- 激活nexusRepo这个profile:只有激活才生效 -->
     <!-- <activeProfile>nexusProfile</activeProfile> -->
</ activeProfiles >
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值