Maven本地镜像

时间:2017-05-31 08:42:14

标签: maven local artifactory multiple-repositories

我在本地运行JFrog's Artifactory,我将工件上传到默认的libs-snapshot-local存储库。它还配置为使用JCenter作为远程存储库 Maven配置了以下settings.xml:

<settings>
    <mirrors>
        <mirror>
            <id>jcenter</id>
            <name>jcenter</name>
            <url>http://172.18.0.1:8081/artifactory/jcenter</url>
            <mirrorOf>*,!libs-snapshot-local</mirrorOf>
        </mirror>
        <mirror>
            <id>libs-snapshot-local</id>
            <name>libs-snapshot-local</name>
            <url>http://172.18.0.1:8081/artifactory/libs-snapshot-local</url>
            <mirrorOf>libs-snapshot-local</mirrorOf>
        </mirror>
    </mirrors>

    <profiles>
        <profile>
            <repositories>
                <repository>
                    <id>jcenter</id>
                    <name>jcenter</name>
                    <url>http://172.18.0.1:8081/artifactory/jcenter</url>
                    <snapshots><enabled>false</enabled></snapshots>
                </repository>
                <repository>
                    <id>libs-snapshot-local</id>
                    <name>libs-snapshot-local</name>
                    <url>http://172.18.0.1:8081/artifactory/libs-snapshot-local</url>
                    <snapshots><enabled>true</enabled></snapshots>
                </repository>
            </repositories>

            <pluginRepositories>
                <pluginRepository>
                    <id>jcenter</id>
                    <name>jcenter</name>
                    <url>http://172.18.0.1:8081/artifactory/jcenter</url>
                    <snapshots><enabled>false</enabled></snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>libs-snapshot-local</id>
                    <name>libs-snapshot-local</name>
                    <url>http://172.18.0.1:8081/artifactory/libs-snapshot-local</url>
                    <snapshots><enabled>true</enabled></snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
</settings>

当我运行编译过程时,Maven似乎从JCenter中取出了所有内容:

[INFO] Downloading: http://172.18.0.1:8081/artifactory/jcenter/org/apache/maven/plugins/maven-javadoc-plugin/2.10.4/maven-javadoc-plugin-2.10.4.jar

即使 - 根据Artifactory,该神器是在libs-snapshot-local内。

为什么它不首先使用本地的,有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:0)

我并不完全清楚你想要达到的目标。

通常,您不在settings.xml中设置两个镜像,而是使用您在Artifactory中定义的存储库组(也称为虚拟存储库)。在此组中,您可以设置存储库的顺序,以便始终首先询问您最喜欢的存储库。通常,您首先放置“本地”存储库,然后放置“远程”存储库(我使用的是Nexus,因此我无法确切地告诉您如何在Artifactory中设置它)。

尽管如此,如果你不遵循这个建议并没有太大的危害,因为Artifactory会缓存已经请求过的工件(当然你的Maven也会在你的计算机上缓存这些工件)。