简体   繁体   English

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

[英]Why does maven search my private dependency jar from maven central server first every time?

I have a jar named brandstore-repository in my maven private servers (nexus), 我的Maven私人伺服器(连结)中有一个名为brandstore-repository的jar,

why maven first search it from maven center server every time? 为什么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

In my setting.xml file, I have already set my private servers (nexus) "http://10.8.12.100/nexus/content/groups/public" on top 在我的setting.xml文件中,我已经在顶部设置了我的私有服务器(nexus)“ http://10.8.12.100/nexus/content/groups/public”

and activeProfiles i set "profile-baozun" before "maven-home" 和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>

Maven has no way of knowing where your maven coordinates point to without checking the repository indexes. 如果不检查存储库索引,Maven无法知道您的Maven坐标指向何处。 I would suggest that you have your nexus proxy the central maven repository and others, and then add a mirror stanza in settings.xml. 我建议您在中央Maven存储库和其他存储库中使用您的联系代理,然后在settings.xml中添加一个镜像节

This way all requests will go to nexus, and if nexus doesn't have the artifact, it will cache it and serve it, so that next time, you will get it even faster. 这样,所有请求都将发送到nexus,如果nexus没有工件,它将对其进行缓存并提供服务,以便下次您可以更快地获得它。

I would suggest to set up the settings.xml to only point to a repository group and then adding other proxy and hosted repositories to the group in Nexus. 我建议将settings.xml设置为仅指向存储库组,然后将其他代理和托管存储库添加到Nexus组中。 That way you do not have to reconfigure the settings.xml anymore after you did the first install. 这样,您无需在首次安装后重新配置settings.xml。

Check out a sample settings.xml in the Nexus book . Nexus书中查看一个示例settings.xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM