maven setting多仓库配置方式

 更新时间:2024年05月06日 10:32:35   作者:Mr-Wanter  
这篇文章主要介绍了maven setting多仓库配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

前言

maven setting 通常公司都有私 服地址,但不是所有包私 服上都有,这时就要用阿里云或者其他地址去拉包。

那么我们可以直接设置setting 使其拉包时第一个地址拉取不到自动到第二个地址拉取以此类推可设置多个仓库地址进行补充。

一 、setting文件

<?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>D:\software\dev\apache-maven-3.6.3\Repositories</localRepository>
  <pluginGroups></pluginGroups>
  <proxies></proxies>
  <servers></servers>
  <mirrors></mirrors>

  <profiles>
    <profile>
      <id>aliyun</id> 
      <repositories>
        <repository>
          <id>aliyun</id> 
          <url>https://maven.aliyun.com/repository/public</url> 
          <releases>
            <enabled>true</enabled>
          </releases> 
          <snapshots>
            <enabled>true</enabled> 
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>
	<profile>
		<id>private</id>
		<repositories>
			<repository>
				<id>maven-releases</id>
				<name>User Porject Release</name>
				<url>http://私服 地址/nexus/repository/maven-releases/</url>
				<snapshots>
					<enabled>false</enabled>
				</snapshots>
				<releases>
					<enabled>true</enabled>
				</releases>
			</repository>
			<repository>
				<id>maven-snapshots</id>
				<name>User Porject Snapshot</name>
				<url>http://私服 地址/nexus/repository/maven-snapshots/</url>
				<snapshots>
					<enabled>true</enabled>
					<updatePolicy>always</updatePolicy>
				</snapshots>
			</repository>
			<!-- 也可以把阿里云等仓库地址直接在这里补充 -->
			<repository>
				<id>com.e-iceblue</id>
				<name>e-iceblue</name>
				 <url>http://repo.e-iceblue.cn/repository/maven-public/</url>
			</repository>
		</repositories>
	</profile>
<!--    <profile>-->
<!--      <id>repo1</id>-->
<!--      <repositories>-->
<!--        <repository>-->
<!--          <id>repo1</id>-->
<!--          <url>https://repo1.maven.org/maven2</url>-->
<!--          <releases>-->
<!--            <enabled>true</enabled>-->
<!--          </releases>-->
<!--          <snapshots>-->
<!--            <enabled>true</enabled>-->
<!--            <updatePolicy>always</updatePolicy>-->
<!--          </snapshots>-->
<!--        </repository>-->
<!--      </repositories>-->
<!--    </profile>-->
<!--    <profile>-->
<!--      <id>repo2</id>-->
<!--      <repositories>-->
<!--        <repository>-->
<!--          <id>repo2</id>-->
<!--          <url>https://repo2.maven.org/maven2</url>-->
<!--          <releases>-->
<!--            <enabled>true</enabled>-->
<!--          </releases>-->
<!--          <snapshots>-->
<!--            <enabled>true</enabled>-->
<!--            <updatePolicy>always</updatePolicy>-->
<!--          </snapshots>-->
<!--        </repository>-->
<!--      </repositories>-->
<!--    </profile>-->
  </profiles>

  <activeProfiles>
    <activeProfile>aliyun</activeProfile>
    <activeProfile>private</activeProfile>
<!--  <activeProfile>repo1</activeProfile>-->
<!--  <activeProfile>repo2</activeProfile>-->
    </activeProfiles>
</settings>

二、其他问题

1.maven 默认有一个setting文件,如果我们的setting文件有很多,而默认setting中的mirror 直接指定了仓库路径,此时无论引用哪个setting文件,都会首先到默认setting内指定的仓库中拉取。

如下图所示,我的默认setting文件如此设置后,我指定了另外的setting文件,但是他会去D:\software\dev\apache-maven-3.6.3\Repositories\hlj路径下寻包

寻找不到直接报错

Could not find artifact xxx in public (file://D:\software\dev\apache-maven-3.6.3\Repositories\hlj)

最好只保留一个setting文件

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • swing中Tree与滚动条用法实例分析

    swing中Tree与滚动条用法实例分析

    这篇文章主要介绍了swing中Tree与滚动条用法,以实例形式分析了java基于swing实现图形界面的使用技巧,需要的朋友可以参考下
    2015-09-09
  • Spring Cloud Gateway实现分布式限流和熔断降级的示例代码

    Spring Cloud Gateway实现分布式限流和熔断降级的示例代码

    这篇文章主要介绍了Spring Cloud Gateway实现分布式限流和熔断降级的示例代码,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
    2025-06-06
  • 使用Springboot实现OAuth服务的示例详解

    使用Springboot实现OAuth服务的示例详解

    OAuth(Open Authorization)是一个开放标准,用于授权第三方应用程序访问用户资源,而不需要共享用户凭证。本文主要介绍了如何使用Springboot实现一个OAuth服务,需要的可以参考一下
    2023-05-05
  • Spring Boot常用注解(经典干货)

    Spring Boot常用注解(经典干货)

    Spring Boot是一个快速开发框架,快速的将一些常用的第三方依赖整合,全部采用注解形式,内置Http服务器,最终以Java应用程序进行执行,这篇文章主要介绍了Spring Boot常用注解(绝对经典),需要的朋友可以参考下
    2023-01-01
  • Java Stream API详解与使用示例详解

    Java Stream API详解与使用示例详解

    Java Stream API 是一个功能强大的工具,适用于处理集合和数据流,本文全面介绍了 Java Stream API 的概念、功能以及如何在 Java 中有效地使用它进行集合和数据流的处理,感兴趣的朋友跟随小编一起看看吧
    2024-05-05
  • SpringBoot实现联表查询的代码详解

    SpringBoot实现联表查询的代码详解

    这篇文章主要介绍了SpringBoot中如何实现联表查询,文中通过代码示例和图文结合的方式讲解的非常详细,对大家的学习或工作有一定的帮助,需要的朋友可以参考下
    2024-05-05
  • IDEA提示 add *** to custom tags问题及解决

    IDEA提示 add *** to custom tags问题及解决

    文章介绍了如何在文档注释中添加自定义注解(@xxx),并提供了添加和删除注解的方法,总结了个人经验,希望对大家有所帮助
    2024-12-12
  • Mybatis-plus null值更新不生效问题解决

    Mybatis-plus null值更新不生效问题解决

    在使用Mybatis-plus进行数据更新时,默认策略是NOT_NULL,即null值不会被更新到数据库,解决方法包括设置全局field-strategy、对特定字段设置field-strategy或使用UpdateWrapper方式更新,下面就来介绍一下
    2024-10-10
  • springcloud gateway高级功能之集成apollo后动态刷新路由方式

    springcloud gateway高级功能之集成apollo后动态刷新路由方式

    这篇文章主要介绍了springcloud gateway高级功能之集成apollo后动态刷新路由方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-08-08
  • 最简单的在IntelliJ IDEA导入一个本地项目教程(图文)

    最简单的在IntelliJ IDEA导入一个本地项目教程(图文)

    这篇文章主要介绍了最简单的在IntelliJ IDEA导入一个本地项目教程(图文),文中通过图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-08-08

最新评论