怎么给Maven配置多仓库?

情况

Maven私库一般都会配置连接中央仓库,但是私库只能使用公司的网进行连接。回到家里自己学习新技术新建项目就无法下载驱动,目前解决方法要不连接公司VPN,要不写个阿里云的settings文件,项目中手动切换,有点麻烦。

尝试

想尝试下能不能在Maven的settings文件中同时配置公司私库和阿里仓库。百度了很久,看了一堆文章。配置多个mirror铁定没用,Maven不会按顺序查找。然后想在profiles中配置多个私库,都激活,还是失败(不清楚是我配错了还是没用)

期望

我希望达到的效果是新建项目,刷新Maven,先本地仓库找,然后到阿里仓库找,最后到公司私库找,有没有大神知道这个该怎么配啊???

阅读 2.1k
1 个回答
配置多个mirror铁定没用,Maven不会按顺序查找

这个有用啊,怎么会没用,我都是这么配置是,是不是你们公司maven还有账号密码,你还需要配置servers

<?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">
    
    <pluginGroups />
    <proxies />
    <servers>
    <server>
       <id>snapshots</id>
       <username>xxx</username>
       <password>xxxxxxxx</password>
   </server>
   <server>
       <id>xxx-maven-partner</id>
       <username>xxx</username>
       <password>xxxxxxxxxx</password>
   </server>
  </servers>
    
    <!-- maven自动下载的jar包,会存放到该目录下 -->
    <localRepository>${user.home}/.m2/repository</localRepository>
    
    <mirrors>
        <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <url>http://repo1.maven.org/maven2/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>
        <mirror>
            <id>ibiblio</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
        </mirror>
        <mirror>
            <id>jboss-public-repository-group</id>
            <mirrorOf>central</mirrorOf>
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>
        </mirror>
        <mirror>
            <id>google-maven-central</id>
            <name>Google Maven Central</name>
            <url>https://maven-central.storage.googleapis.com
            </url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <!-- 中央仓库在中国的镜像 -->
        <mirror>
            <id>maven.net.cn</id>
            <name>oneof the central mirrors in china</name>
            <url>http://maven.net.cn/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>xxxx-maven-partner</id>
            <name>oneof the central mirrors in china</name>
            <url>xxxxxxxxxxxxxxxxx</url>
            <mirrorOf>xxxxx-maven-partner</mirrorOf>
        </mirror>
    </mirrors>
    
</settings>

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题