使用maven 如何实现配置多个仓库

发布时间:2020-11-06 16:45:00 作者:Leah
来源:亿速云 阅读:897

这期内容当中小编将会给大家带来有关使用maven 如何实现配置多个仓库,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

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>

上述就是小编为大家分享的使用maven 如何实现配置多个仓库了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. maven以及idea使用maven
  2. maven多仓库配置教程

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

maven 仓库配置

上一篇:使用PHP编写一个计算器功能

下一篇:使用MyBatis如何查询SELECT

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》