【maven】仓库的优先级顺序

在maven中,仓库可以分为:本地仓库、远程仓库。
远程仓库可以分为:中央仓库、私服仓库。
中央仓库是maven官方指定的仓库,可以理解为“寻找的最后一站”。
私服仓库可以是自己建的,也可以是其它主体建的(比如aliyun的maven仓库,jboss的maven仓库等)。
私服可以分为:全局应用的私服仓库、应用到项目自身的私服仓库。

maven寻找得顺序大致可以理解为:
1,在本地仓库中寻找,如果没有则进入下一步。
2,在全局应用的私服仓库中寻找,如果没有则进入下一步。
3,在项目自身的私服仓库中寻找,如果没有则进入下一步。
4,在中央仓库中寻找,如果没有则终止寻找。

补充:
1,如果在找寻的过程中,如果发现该仓库有镜像设置,则用镜像的地址代替。
2,如果仓库的id设置成“central”,则该配置会覆盖maven默认的中央仓库配置。

以上,通过实践得来的,可能不全面,仅当参考。

科普一下几种仓库的设置:

pom中的repository:

<repositories>
    <repository>
        <id>dsdf</id>
        <releases>
            <enabled>true</enabled>
        </releases>
        <url>http://222.197.XXXXXX/nexus/content/groups/public/</url>
    </repository>
</repositories>

profile中的仓库是在maven的设置文件(maven安装目录/conf/settings.xml)

<profile>
    <id>nexus</id>
    <repositories>
        <repository>
            <id>sonatype-forge</id>
            <url>http://repository.sonatype.org/content/groups/forge/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>sonatype-forge</id>
            <url>http://repository.sonatype.org/content/groups/forge/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</profile>

使用下面代码来激活profile

<activeProfiles>
    <activeProfile>nexus</activeProfile>
</activeProfiles>

maven profile也是有优先级别

  1. 在settings.xml中的profile优先级高于pom中的
  2. 同在settings.xml的properties,如果都激活了,根据profile定义的先后顺序来进行覆盖取值,后面定义的会覆盖前面,其properties为同名properties中最终有效。并不是根据activeProfile定义的顺序 。
  3. 如果有user setting和globel settings,则两者合并,其中重复的配置,以user settings为准。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在Maven中,任何一个依赖、插件或者项目构建的输出,都可以称之为构件。 Maven在某个统一的位置存储所有项目的...
    三也视界阅读 2,147评论 0 4
  • 五. 仓库 在Maven中,任何一个依赖、插件或者项目构建的输出,都可以称之为 构件。Maven在某个统一的位置存...
    wind_sky阅读 1,510评论 0 0
  • 在 Maven 的术语中,仓库是一个位置(place)。Maven 仓库是项目中依赖的第三方库,这个库所在的位置叫...
    41uLove阅读 7,114评论 2 3
  • 在Maven世界中,依赖、插件、项目构建完成后输出的jar包都可以看作是一个构件,任何一个构件都有一组坐标唯一标识...
    SonyaBaby阅读 629评论 0 0
  • S带上了耳机,眼前的一切都与她隔绝开来。虽是初春的好天气,花都开的正鲜艳,行人也都驻足欣赏,还有不少怀着好心情的年...
    灰台阅读 120评论 0 0