Maven--配置 Maven 从 Nexus 下载构件

在 POM 中配置:

 1 <project>
 2     ...
 3     <repositories>
 4         <repository>
 5             <id>nexus</id>
 6             <name>Nexus</name>
 7             <url>http://10.70.8.36:8081/nexus/content/groups/public/</url>
 8             <releases>
 9                 <enabled>true</enabled>
10             </releases>
11             <snapshots>
12                 <enabled>true</enabled>
13             </snapshots>
14         </repository>
15     </repositories>
16     <pluginRepositories>
17         <pluginRepository>
18             <id>nexus</id>
19             <name>Nexus</name>
20             <url>http://10.70.8.36:8081/nexus/content/groups/public/</url>
21             <releases>
22                 <enabled>true</enabled>
23             </releases>
24             <snapshots>
25                 <enabled>true</enabled>
26             </snapshots>
27         </pluginRepository>
28     </pluginRepositories>
29     ...
30 </project>

 

 

在 settings.xml 中配置:

settings.xml 并不支持直接配置 repositories 和 pluginRepositories,Maven 提供了 profile 机制,能让为用户将仓库配置放到 settings.xml 中的 profile 中。

 1 <settings>
 2     ...
 3     <profiles>
 4         <profile>    
 5         <id>nexus</id>
 6         <repositories>
 7             <repository>
 8                 <id>nexus</id>
 9                 <name>Nexus</name>
10                 <url>http://10.70.8.36:8081/nexus/content/groups/public/</url>
11                 <releases>
12                      <enabled>true</enabled>     
13                 </releases>
14                 <snapshots>
15                      <enabled>true</enabled>
16                 </snapshots>
17             </repository>
18         </repositories>
19         <pluginRepositories>
20             <pluginRepository>
21                 <id>nexus</id>
22                 <name>Nexus</name>
23                 <url>http://10.70.8.36:8081/nexus/content/groups/public/</url>
24                 <releases>
25                      <enabled>true</enabled>     
26                 </releases>
27                 <snapshots>
28                      <enabled>true</enabled>
29                 </snapshots>
30             </pluginRepository>
31         </pluginRepositories>
32     </profile>
33     </profiles>
34 
35     <activeProfiles>
36         <activeProfile>nexus</activeProfile>
37     </activeProfiles>
38     ...
39 </settings>

该配置中使用用一个  <id>  为 nexus 的  <profile> ,这个 profile 包含了相关的仓库配置,同时配置中又使用  <activeProfile>  将 nuxus 这个 profile 激活,这样当执行 Maven 构建的时候,激活的 profile 会将仓库配置应用到项目中去。

 

配置了上述配置,Maven 除了从 Nexus 下载构件之外,还会不时地访问中央仓库 central,如果希望所有 Maven 下载请求都仅仅通过 Nexus,这个时候需要配置镜像。

 

 1 <settings>
 2     ...
 3     <mirrors>
 4         <mirror>
 5             <id>nexus</id>
 6             <mirrorOf>*</mirrorOf>
 7          <url>http://10.70.8.36:8081/nexus/content/groups/public/</url>
 8         </mirror>
 9     </mirrors>
10     <profiles>
11         <profile>    
12         <id>nexus</id>
13         <repositories>
14             <repository>
15                 <id>nexus</id>
16                 <name>Nexus</name>
17                 <url>http://10.70.8.36:8081/nexus/content/groups/public/</url>
18                 <releases>
19                      <enabled>true</enabled>     
20                 </releases>
21                 <snapshots>
22                      <enabled>true</enabled>
23                 </snapshots>
24             </repository>
25         </repositories>
26         <pluginRepositories>
27             <pluginRepository>
28                 <id>nexus</id>
29                 <name>Nexus</name>
30                 <url>http://10.70.8.36:8081/nexus/content/groups/public/</url>
31                 <releases>
32                      <enabled>true</enabled>     
33                 </releases>
34                 <snapshots>
35                      <enabled>true</enabled>
36                 </snapshots>
37             </pluginRepository>
38         </pluginRepositories>
39     </profile>
40     </profiles>
41 
42     <activeProfiles>
43         <activeProfile>nexus</activeProfile>
44     </activeProfiles>
45     ...
46 </settings>    

仓库及插件仓库配置的 id 都是 central,他们覆盖了超级 POM 中央仓库的配置,它们的 url 已经无关紧要,因为所有的请求都会通过镜像访问私服地址。配置仓库及插件仓库的主要目的是开启对快照版本下载的支持,当 Maven 需要下载发布版或快照版构件的时候,它首先检查 central,看该类型的构件是否支持,得到正面的回答之后,再根据镜像匹配规则转而访问私服仓库地址。

转载于:https://www.cnblogs.com/microcat/p/7243604.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值