maven 配置多个仓库的方法

作者:itprobie-菜鸟程序员 时间:2021-06-09 03:30:24 

1>方法一

之前在配置 Maven 的 settings.xml 时,都会设置 mirror 节点,例如:


<mirrors>
 <mirror>
   <id>alimaven</id>
   <name>aliyun maven</name>
   <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
   <mirrorOf>central</mirrorOf>
 </mirror>
</mirrors>

然后第一想法就是在 mirrors 节点下多增加几个 mirror,然而并不可以。正确的操作是在 profiles 节点下配置多个 profile,而且配置之后要激活。例如:

配置profiles


<profiles>
 <profile>
  <id>boundlessgeo</id>
  <repositories>
   <repository>
    <id>boundlessgeo</id>
    <url>https://repo.boundlessgeo.com/main/</url>
    <releases>
     <enabled>true</enabled>
    </releases>
    <snapshots>
     <enabled>true</enabled>
     <updatePolicy>always</updatePolicy>
    </snapshots>
   </repository>
  </repositories>
 </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>
<profiles>

通过配置 activeProfiles 子节点激活


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

如果在IDE里,记得要更新生效,然后就可以了。

2> 方法二

在项目中添加多个仓库,是通过修改项目中的pom文件实现的。
思路:在项目中pom文件的repositories节点(如果没有手动添加)下添加多个repository节点,每个repository节点是一个仓库。 


<repositories>
   <repository>
     <!-- id必须唯一 -->
     <id>jboss-repository</id>
     <name>jboss repository</name>
     <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
   </repository>
   <repository>
     <id>aliyun-repository</id>
     <name>aliyun repository</name>
     <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
   </repository>

<repository>
    <id>奇葩仓库</id>
    <url>https://奇葩仓库/public/</url>
   </repository>

</repositories>

来源:https://www.cnblogs.com/guohu/p/12208094.html

标签:maven,仓库,配置
0
投稿

猜你喜欢

  • Java基础教程之String深度分析

    2022-08-19 05:42:15
  • spring cglib 与 jdk 动态代理

    2021-07-19 20:28:43
  • java中Date类和Strng类的灵活转化

    2022-12-09 07:47:24
  • 使用idea+gradle编译spring5.x.x源码分析

    2022-05-13 15:13:31
  • java多线程加锁以及Condition类的使用实例解析

    2023-08-07 07:25:30
  • Java实现json数据处理的常用脚本分享

    2022-07-27 15:21:39
  • C#中的文件路径获取函数和文件名字获取函数小结

    2023-10-18 10:28:20
  • 关于Springboot数据库配置文件明文密码加密解密的问题

    2023-11-25 03:29:46
  • MybatisPlus字段类型转换的实现示例

    2022-12-09 22:29:13
  • Java图形用户界面设计(Swing)的介绍

    2022-08-23 03:29:37
  • 浅谈关于Mybatis的mapper-locations配置问题

    2023-09-24 06:06:16
  • 基于Java swing组件实现简易计算器

    2023-03-29 02:10:07
  • Java11中基于嵌套关系的访问控制优化详解

    2021-12-28 18:54:20
  • 防止未登录用户操作—基于struts2拦截器的简单实现

    2021-06-11 13:21:00
  • Mybatis generator自动生成代码插件实例解析

    2022-06-04 22:52:33
  • Unity3D实现攻击范围检测

    2023-07-02 12:12:39
  • Opencv EigenFace人脸识别算法详解

    2023-07-21 19:30:17
  • 一文带你了解如何正确使用Java中的字符串常量池

    2022-07-13 01:35:30
  • Java实现五子棋的基础方法

    2021-07-11 12:32:08
  • 基于list stream: reduce的使用实例

    2021-07-21 06:54:52
  • asp之家 软件编程 m.aspxhome.com