Maven先本地找jar,找不到再远程的配置

767 阅读1分钟

本文经过笔者工作中亲自测试验证,确实可用,找了很多都不好使,如果你也遇到需要maven先从本地仓库找jar,找不到才从远程仓库找,可参考如下配置,有问题评论区交流,谢谢。

<?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:\m2\repository</localRepository>

    <pluginGroups>
    </pluginGroups>

    <proxies>
    </proxies>

    <servers>
        <!-- 配置私服的用户名 密码 -->
        <server>
            <id>xxxx-maven-rep</id>
            <username>admin</username>
            <password>xxxxxx</password>
        </server>
       
    </servers>


    <mirrors>
        <!-- 先从本地找 -->
        <mirror>
            <id>central</id>
            <mirrorOf>*</mirrorOf>
            <name>central</name>
            <url>file://D:\m2\repository</url>
        </mirror>

        <!-- 本地没有从私服找 -->
        <mirror>
            <id>xxxx-maven-rep</id>
            <name>maven-rep</name>
            <url>http://songxiaohei.com/maven/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>

    <profiles>
        <profile>
            <id>new</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <repositories>
                <repository>
                    <id>xxxx-maven-rep</id>
                    <name>maven-rep</name>
                    <url>http://songxiaohei.com/maven/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>
    </profiles>


    <activeProfiles>
        <activeProfile>new</activeProfile>
    </activeProfiles>

</settings>