配置Maven从私服下载构件

--------------------siwuxie095

  

  

  

  

  

  

  

  

  

配置 Maven 从私服下载构件

  

  

从 Nexus 私服下载构件的配置方法共有三种

  

1法一

  

在 pom.xml 的 project 标签中添加如下内容

  

<repositories>

<repository>

 

<id>nexus</id>

<name>Nexus</name>

<url>http://localhost:8081/nexus/content/groups/public/</url>

 

<releases>

<enabled>true</enabled>

</releases>

 

<snapshots>

<enabled>true</enabled>

</snapshots>

 

</repository>

</repositories>

 

<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

 

<pluginRepositories>

<pluginRepository>

 

<id>nexus</id>

<name>Nexus</name>

<url>http://localhost:8081/nexus/content/groups/public/</url>

 

<releases>

<enabled>true</enabled>

</releases>

 

<snapshots>

<enabled>true</enabled>

</snapshots>

 

</pluginRepository>

</pluginRepositories>

  

注:分别配置仓库和插件仓库

  

  

  

  

2法二

  

1)在 settings.xml 的 profiles 标签中添加如下内容

  

<profile>

 

<id>nexus</id>

  

<repositories>

<repository>

  

<id>nexus</id>

<name>Nexus</name>

<url>http://localhost:8081/nexus/content/groups/public/</url>

 

<releases>

<enabled>true</enabled>

</releases>

 

<snapshots>

<enabled>true</enabled>

</snapshots>

  

</repository>

</repositories>

  

<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

  

<pluginRepositories>

<pluginRepository>

  

<id>nexus</id>

<name>Nexus</name>

<url>http://localhost:8081/nexus/content/groups/public/</url>

  

<releases>

<enabled>true</enabled>

</releases>

 

<snapshots>

<enabled>true</enabled>

</snapshots>

  

</pluginRepository>

</pluginRepositories>

  

</profile>

  

注:使用 id 为 nexus 的 profile 分别配置仓库和插件仓库

  

  

  

2)在 settings.xml 的 activeProfiles 标签中添加如下内容

  

<activeProfile>nexus</activeProfile>

  

注:将 id 为 nexus 的 profile 激活

  

  

  

  

3法三(建议):

  

1)在 settings.xml 的 mirrors 标签中添加如下内容

  

<mirror>

<id>nexus</id>

<name>Nexus</name>

<url>http://localhost:8081/nexus/content/groups/public/</url>

<mirrorOf>*</mirrorOf>

</mirror>

  

注:配置一个匹配任何仓库的镜像,其地址为 Nexus 私服

  

  

  

2)在 settings.xml 的 profiles 标签中添加如下内容

  

<profile>

 

<id>nexus</id>

  

<repositories>

<repository>

  

<id>central</id>

<name>Central</name>

<url>http://central</url>

 

<releases>

<enabled>true</enabled>

</releases>

 

<snapshots>

<enabled>true</enabled>

</snapshots>

  

</repository>

</repositories>

  

<!-- ++++++++++++++++++++++++++ -->

  

<pluginRepositories>

<pluginRepository>

  

<id>central</id>

<name>Central</name>

<url>http://central</url>

  

<releases>

<enabled>true</enabled>

</releases>

 

<snapshots>

<enabled>true</enabled>

</snapshots>

  

</pluginRepository>

</pluginRepositories>

  

</profile>

  

注:使用 id 为 nexus 的 profile 分别配置仓库和插件仓库,

但仓库和插件仓库的 id 都为 central,这将覆盖超级 POM

中央仓库的配置,而 url 已无关紧要,因为所有的请求都会

通过镜像访问私服地址

  

配置仓库和插件仓库的主要目的是开启对快照版本构件下载

的支持

  

  

  

3)在 settings.xml 的 activeProfiles 标签中添加如下内容

  

<activeProfile>nexus</activeProfile>

  

注:将 id 为 nexus 的 profile 激活

  

  

  

  

  

附:

  

法一

针对当前 Maven 项目

法二

针对所有 Maven 项目

法三

针对所有 Maven 项目

  

  

法二和法三虽然都可以一劳永逸,但法二除了从 Nexus 私服

下载构件之外,还会不时访问中央仓库

  

我们希望的是所有 Maven 下载请求都仅仅通过 Nexus 私服,

以全面发挥私服的作用,而法三刚好做到了这点

  

  

  

  

  

  

  

  

  

  

【made by siwuxie095】

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值