Maven

目的

        记录下自己在项目实际使用时遇见的问题,不做科普,仅为记录!!! 

依赖查找顺序

  1. 在本地仓库中寻找
  2. 在全局配置的远程仓库(settings.xml中配置的并有激活)中寻找(如果被mirror拦截,则从mirror查询)
  3. 在项目自身配置的远程仓库(pom.xml)中寻找(如果被mirror拦截,则从mirror查询)
  4. 在中央仓库中寻找(如果被mirror拦截,则从mirror查询)

  如果在找寻的过程中,如果发现该仓库有镜像设置,则用镜像的地址代替。例如现在进行到要在respository A仓库中查找某个依赖,但A仓库配置了mirror,则会转到从A的mirror中查找该依赖,不会再从A中查找。

settings.xml中配置的profile(激活的)下的respository优先级高于项目中pom文件配置的respository。

如果仓库的id设置成“central”,则该仓库会覆盖maven默认的中央仓库配置

Maven 镜像配置 mirror

        简单而言, mirror可以拦截对远程仓库的请求 , 改变对目标仓库的下载地址。

        如果mavensetting.xml中配置了镜像 , 而且镜像配置的规则中匹配到目标仓库时 ,
maven认为目标仓库被镜像了, 不会再去被镜像仓库下载依赖jar包, 而是直接去镜像仓库下载。

下面是真实的镜像配置:

<mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>*</mirrorOf>  //代理仓库配置
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

mirrorOf * 就意味着匹配所有的仓库,拦截maven对仓库的请求,将对真实仓库请求的地址更改为镜像地址。

配置mirrorof 有多种形式:

        mirrorOf=“*”  //mirror一切,所有仓库请求全部重定向到镜像地址

        mirrorOf=repo-1 //镜像repo-1,对repo-1仓库访问重定向到镜像地址

        mirrorOf=*,!repo-1  //!表示非运算,排除你配置的repo-1仓库,其他仓库都被镜像了。

        mirrorOf=external:*  //如果本地库存在就用本地库的,如果本地没有所有下载就用mirror配置的url下载

Maven的profile配置

        项目中经常会在Maven中setting文件中配置profile,具体配置如下:

<profiles>
    <profile>
        <id>nexus</id>
        <repositories>
            <repository>
                <id>central</id>
                <url>http://xxx/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>xxx-snapshots</id>
                <url>https://xxx/</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>daily</updatePolicy>
                </snapshots>
            </repository>
        </repositories>
    </profile> 
  </profiles>

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

个人理解:

profile是maven用来隔离不同环境的配置,例如:

  • <repositories>
  • <pluginRepositories>
  • <dependencies>
  • <plugins>
  • <properties> 
  • <modules>
  • <reporting>
  • <dependencyManagement>
  • <distributionManagement> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值