为什么maven每次都首先从maven中央服务器搜索我的私有依赖jar?

fei*_*ong 1 nexus maven

我在我的maven私人服务器(nexus)中有一个名为brandstore-repository的jar,

为什么maven每次都会从maven中心服务器上搜索它?

[artifact:mvn] Downloading: http://search.maven.org/remotecontent?filepath=/com/jumbo/brandstore/brandstore-repository/4.0.0/brandstore-repository-4.0.0.pom
[artifact:mvn] Downloading: http://repository.jboss.com/maven2/com/jumbo/brandstore/brandstore-repository/4.0.0/brandstore-repository-4.0.0.pom
[artifact:mvn] Downloading: https://oss.sonatype.org/content/repositories/snapshots//com/jumbo/brandstore/brandstore-repository/4.0.0/brandstore-repository-4.0.0.pom
[artifact:mvn] Downloading: http://10.8.12.100/nexus/content/groups/public/com/jumbo/brandstore/brandstore-repository/4.0.0/brandstore-repository-4.0.0.pom
[artifact:mvn] 1K downloaded
[artifact:mvn] Downloading: http://search.maven.org/remotecontent?filepath=/com/jumbo/brandstore/brandstore/4.0.0/brandstore-4.0.0.pom
[artifact:mvn] Downloading: http://repository.jboss.com/maven2/com/jumbo/brandstore/brandstore/4.0.0/brandstore-4.0.0.pom
[artifact:mvn] Downloading: https://oss.sonatype.org/content/repositories/snapshots//com/jumbo/brandstore/brandstore/4.0.0/brandstore-4.0.0.pom
[artifact:mvn] Downloading: http://10.8.12.100/nexus/content/groups/public/com/jumbo/brandstore/brandstore/4.0.0/brandstore-4.0.0.pom
[artifact:mvn] 17K downloaded
[artifact:mvn] Downloading: http://search.maven.org/remotecontent?filepath=/com/jumbo/brandstore/brandstore-repository/4.0.0/brandstore-repository-4.0.0.jar
[artifact:mvn] Downloading: http://repository.jboss.com/maven2/com/jumbo/brandstore/brandstore-repository/4.0.0/brandstore-repository-4.0.0.jar
[artifact:mvn] Downloading: https://oss.sonatype.org/content/repositories/snapshots//com/jumbo/brandstore/brandstore-repository/4.0.0/brandstore-repository-4.0.0.jar
[artifact:mvn] Downloading: http://10.8.12.100/nexus/content/groups/public/com/jumbo/brandstore/brandstore-repository/4.0.0/brandstore-repository-4.0.0.jar
[artifact:mvn] 913K downloaded
Run Code Online (Sandbox Code Playgroud)

在我的setting.xml文件中,我已经在顶部设置了我的私人服务器(nexus)"http://10.8.12.100/nexus/content/groups/public"

和activeProfiles我在"maven-home"之前设置了"profile-baozun"

<profiles>
        <profile>
            <id>profile-baozun</id>
            <repositories>
                <repository>
                    <id>public</id>
                    <url>http://10.8.12.100/nexus/content/groups/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>

                <repository>
                    <id>loxia2</id>
                    <url>http://loxia2.googlecode.com/svn/repository</url>
                    <releases>
                        <enabled>true</enabled>
                        <checksumPolicy>warn</checksumPolicy>
                    </releases>
                </repository>
            </repositories>
        </profile> 

        <profile>
            <id>maven-home</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>http://search.maven.org/remotecontent?filepath=</url>
                </repository>

                <repository>
                    <id>jboss</id>
                    <url>http://repository.jboss.com/maven2</url>
                </repository>

                <repository>
                    <id>sonatype</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
                </repository>
            </repositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>maven-home</activeProfile>
                 <activeProfile>profile-baozun</activeProfile>

    </activeProfiles>
Run Code Online (Sandbox Code Playgroud)

Miq*_*uel 7

Maven无法在不检查存储库索引的情况下知道maven坐标指向的位置.我建议您将nexus代理设置为中央maven存储库和其他存储库,然后在settings.xml中添加镜像节.

这样所有请求都将转到nexus,如果nexus没有工件,它会缓存它并提供服务,这样下次你就可以更快地获得它.