maven2的本地配置了解

本文介绍如何在Maven2中配置多个私有仓库(包括Nexus和Artifactory),实现自动选择可用的服务进行依赖下载及上传。通过示例展示了settings.xml文件的具体配置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

maven2的本地配置了解

其实需求很简单,我本机安装了一个私服nexus,有时也用artifactory,同时公司也有一个私服nexus。
也就是说我平时能用的私服有:
本机
http://localhost:8081/nexus
公司1
http://10.206.19.59:81/nexus
公司2
http://10.206.19.252:8081/artifactory

各个服务有时并不一定都保持开机的,所以我想我的maven2是一个一个去试,连得上哪个用哪个。最近修改了本地的settings.xml配置后,基本实现了这个功能,使用了一段时间后发现没有什么问题,现在将settings.xml配置文件记录一下:
<settings xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>

<profile>
<id>nexus_local</id>
<repositories>
<repository>
<id>nexus_local</id>
<name>local private nexus</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>nexus_local</id>
<name>local private nexus</name>
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>nexus_company</id>
<name>local private nexus</name>
<url>http://10.206.19.59:81/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>nexus_company</id>
<name>local private nexus</name>
<url>http://10.206.19.59:81/nexus/content/groups/public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus_local</id>
<name>local private nexus</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus_local</id>
<name>local private nexus</name>
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus_company</id>
<name>local private nexus</name>
<url>http://10.206.19.59:81/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus_company</id>
<name>local private nexus</name>
<url>http://10.206.19.59:81/nexus/content/groups/public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus_local</activeProfile>
</activeProfiles>
</settings>

我的示例中只给出了nexus的两个服务的配置,其实按照这个思路,再多加几个artifactory或者nexus也无妨。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值