idea中的maven 配置多个仓库

配置 Maven 的 settings.xml 时,单个仓库时候都会设置 mirror 节点,例如:

  <mirrors>
    <mirror>
        <id>nexus</id>
        <mirrorOf>*</mirrorOf>
        <url>http://192.168.0.1:8061/repository/maven-public/</url>
    </mirror>
  </mirrors>

然后,增加mirror节点并不能配置多个仓库。

正确的操作是在 profiles 节点下配置多个 profile,而且配置之后要激活。例如:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>C:\Users\Administrator\.m2\repository</localRepository>
  <pluginGroups>
  </pluginGroups>

  <proxies>
  </proxies>

  <servers>
  </servers>
<!--
  <mirrors>
    <mirror>
        <id>nexus</id>
        <mirrorOf>*</mirrorOf>
        <url>http://106.14.80.25:8061/repository/maven-public/</url>
    </mirror>
  </mirrors>
-->
	<profile>
		<profile> 
		  <id>aliyun</id>  
		  <repositories> 
			<repository> 
			  <id>aliyun</id>  
			  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
			  <releases> 
				<enabled>true</enabled> 
			  </releases>  
			  <snapshots> 
				<enabled>true</enabled>  
				<updatePolicy>always</updatePolicy> 
			  </snapshots> 
			</repository> 
		  </repositories> 
		</profile>
		<profile> 
		  <id>maven-central</id>  
		  <repositories> 
			<repository> 
			  <id>maven-central</id>  
			  <url>http://central.maven.org/maven2/</url>  
			  <releases> 
				<enabled>true</enabled> 
			  </releases>  
			  <snapshots> 
				<enabled>true</enabled>  
				<updatePolicy>always</updatePolicy> 
			  </snapshots> 
			</repository> 
		  </repositories> 
		</profile> 
		<profile> 
		  <id>custom-maven</id>  
		  <repositories> 
			<repository> 
			  <id>custom-maven</id>  
			  <url>http://central.maven.org/maven2/</url>  
			  <releases> 
				<enabled>true</enabled> 
			  </releases>  
			  <snapshots> 
				<enabled>true</enabled>  
				<updatePolicy>always</updatePolicy> 
			  </snapshots> 
			</repository> 
		  </repositories> 
		</profile> 
	</profile> 
	<activeProfiles>
		<activeProfile>aliyun</activeProfile>
		<activeProfile>maven-central</activeProfile>
		<activeProfile>custom-maven</activeProfile>
	</activeProfiles>
</settings>

通过配置 activeProfiles 子节点激活

<activeProfiles>
	<activeProfile>boundlessgeo</activeProfile>
	<activeProfile>aliyun</activeProfile>
	<activeProfile>maven-central</activeProfile>
</activeProfiles>

在IntelliJ IDEA或Eclipse中更新配置文件,以生效。

菜单栏Window——Preferencecs——Maven——User Setting–update Settings applyandclose

然后 maven updateproject。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
多个maven仓库配置的场景下,可以考虑使用Maven多个仓库配置功能来提高构建和依赖管理的灵活性。 首先,在pom.xml文件配置多个仓库,可以通过在`<repositories>`标签下添加多个`<repository>`标签实现。每个`<repository>`标签需要配置仓库的URL、ID等相关信息。 其次,可以根据需要,针对每个仓库配置不同的优先级。Maven解析仓库时,会按照仓库的优先级顺序进行搜索。可以通过在`<repositories>`标签添加`<releases>`和`<snapshots>`标签来分别为发行版和快照版本配置优先级策略。例如,可以将稳定版本的仓库设置为优先级较高的仓库,以确保项目在构建时使用最新的稳定版本依赖。 此外,还可以通过使用统一的父项目,对多个子项目的仓库进行统一配置。通过在父项目的pom.xml文件配置仓库,可以避免在每个子项目重复配置。 另外,Maven还提供了缓存功能,可以通过在`<settings>`标签下的`<localRepository>`标签配置本地仓库路径,以方便构建过程的依赖缓存和重用。 最后,针对国内用户,在配置多个maven仓库时,可以考虑配置国内镜像仓库,以提高依赖下载速度。可以通过在`<settings>`标签下的`<mirrors>`标签配置国内镜像仓库的URL,将官方仓库替换为国内镜像仓库。 总之,通过合理配置多个maven仓库,可以提高项目的构建效率和依赖管理的灵活性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CDialog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值