当前位置: 代码网 > it编程>编程语言>Java > maven中仓库的配置与优先级的实现

maven中仓库的配置与优先级的实现

2025年07月23日 Java 我要评论
1 仓库的具体配置1.1 settings.xml配置本地仓库<settings xmlns="http://maven.apache.org/settings/1.0.0" xmlns:xsi

1 仓库的具体配置

1.1 settings.xml配置本地仓库

<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
   | the path to the local repository maven will use to store artifacts.
   |
   | default: ${user.home}/.m2/repository
  <localrepository>/path/to/local/repo</localrepository>
  -->
	<localrepository>d:\program files\apache-maven-3.6.3\conf\repository</localrepository>
</settings>

1.2 pom.xml配置的仓库

<project>
    <repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
    </repositories>
</project>

1.3 settings.xml配置mirror镜像

<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">
	<mirrors>
		<mirror>
			<id>aliyun-central</id>
			<name>aliyun-central</name>
			<mirrorof>central</mirrorof>
			<url>https://maven.aliyun.com/repository/central</url>
		</mirror>
		<mirror>
			<id>aliyun-spring</id>
			<name>aliyun-spring</name>
			<mirrorof>spring</mirrorof>
			<url>https://maven.aliyun.com/repository/spring</url>
		</mirror>
		<mirror>
			<id>aliyun-spring-plugin</id>
			<name>aliyun-spring-plugin</name>
			<mirrorof>spring-plugin</mirrorof>
			<url>https://maven.aliyun.com/repository/spring-plugin</url>
		</mirror>
	</mirrors>
</settings>

1.4 settings.xml配置profile仓库

<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">
	<servers>
		<server>
			<id>nexus-server</id>
			<username>uname</username>
			<password>pwd</password>
		</server>
	</servers>
	
	<profiles>
		<profile>
			<id>nexus</id>
			<repositories>
				<repository>
					<id>nexus-server</id>
					<name>nexus repository</name>
					<url>https://maven.nexus.com/repository/maven-public/</url>
					<snapshots>
						<enabled>true</enabled>
						<updatepolicy>always</updatepolicy>
					</snapshots>
				</repository>
			</repositories>
		</profile>
	</profiles>

	<!--让配置生效-->
	<activeprofiles>
		<activeprofile>nexus</activeprofile>
	</activeprofiles>
</settings>

2 结论

2.1 mirror中不代理*的拉取顺序

  • settings.xml->本地仓库,如果没有则向下找
  • settings.xml->profile中的仓库,如果没有则向下找
  • pom.xml配置的仓库,如果没有则向下找
  • settings.xml->mirror中代理central的仓库

2.2 mirror中代理了*的拉取顺序

mirror中一旦代理了*,则该配置优先级最高,其他的都不会走了。
但是有一种情况除外,就是mirror中代理了central仓库,那么如果代理*的 mirror中没有,则会找代理的central仓库

  • settings.xml->本地仓库,如果没有则向下找
  • settings.xml->mirror中代理*的仓库,如果没有则向下找
  • settings.xml->mirror中代理central的仓库

到此这篇关于maven中仓库的配置与优先级的实现的文章就介绍到这了,更多相关maven 仓库配置与优先级内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网! 

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com