MangoCool

如何下载maven仓库中的SNAPSHOTS依赖包

2022-09-21 10:42:13   作者:anobody   来源:MangoCool

如何下载maven仓库中的SNAPSHOTS包:

maven下载依赖使用配置顺序:pom.xml-->用户目录下的settings.xml-->maven安装目录下的settings.xml

大部分都是这么配置:

<mirrors>
	<mirror>
		<id>alimaven</id>
		<name>aliyun maven</name>
		<url>https://maven.aliyun.com/repository/central</url>
		<mirrorOf>central</mirrorOf>
	</mirror>
</mirrors>

如果只是配置setting.xml是下载不了SNAPSHOTS包的,需要在pom.xml中配置:

<profiles>
	<profile>
		......
		<repositories>
			<repository>
				<id>maven-public</id>
				<url>https://maven.aliyun.com/repository/central</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>
	</profile>
</profiles>

如果配置了pom.xml,setting.xml就不起作用了

这里能下载SNAPSHOTS包,关键是因为<snapshots><enabled>true</enabled></snapshots>

注:如果pom.xml中元素id值跟setting.xml中元素mirrorOf值相同,就会使用setting.xml中的地址,相当于pom.xml中的url不起作用了,如下配置也是可以的:

<profiles>
	<profile>
		......
		<repositories>
			<repository>
				<id>central</id>
				<url>xx</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>
	</profile>
</profiles>

同时pom.xml可以配置多个repository,并且按照出现的顺序使用,如果第一个可用,就用第一个,否则依次往下寻找可用的,示例如下:

<profiles>
	<profile>
		......
		<repositories>
			<repository>
				<id>maven-public</id>
				<url>https://xxx.aliyun.com/repository/central</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
			<repository>
				<id>maven-public2</id>
				<url>https://maven.aliyun.com/repository/central</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>
	</profile>
</profiles>


标签: maven SNAPSHOTS pom setting

分享:

上一篇tortoiseGit error: unable to create file xxx.java: Filename too long

下一篇mysql错误:execute /opt/lnmpp/mysql/bin/mysql.server failed with errno 2

关于我

崇尚极简,热爱技术,喜欢唱歌,热衷旅行,爱好电子产品的一介码农。

座右铭

当你的才华还撑不起你的野心的时候,你就应该静下心来学习,永不止步!

人生之旅历途甚长,所争决不在一年半月,万不可因此着急失望,招精神之萎葸。

Copyright 2015- 芒果酷(mangocool.com) All rights reserved. 湘ICP备14019394号

免责声明:本网站部分文章转载其他媒体,意在为公众提供免费服务。如有信息侵犯了您的权益,可与本网站联系,本网站将尽快予以撤除。