maven settings配置文件详细

本文介绍了Maven的配置细节,包括LocalRepository设定本地仓库路径,repositories配置远程仓库及拉取规则,mirrors设置仓库代理,servers管理身份认证信息,以及activeProfiles激活特定配置profile。Maven在寻找依赖时,会按顺序检查本地和远程仓库,并遵循特定的配置优先级。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、LocalRepository 本地仓库配置

<localRepository>D:/Users/local/repo</localRepository>

2、repositories里指定要用到的远程仓库,包括远程仓库的唯一标识、地址、名称、怎么用(比如是否可以拉SnapShot的依赖),这里可以多指定一些仓库,maven找依赖的时候,如果本地仓库没有,就在这些远程仓库里从上往下找,找到就下载,全找完还找不到就是找不到了

<repositories>
    <!-- 配置依赖仓库,可以配置多个仓库,maven会按照顺序进行依赖的加载 -->
    <repository>
        <id>central</id>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>snapshots</id>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>rdc-releases</id>
        <url>https://repo.rdc.aliyun.com/repository/73702-release-Kgsln6/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>rdc-snapshots</id>
        <url>https://repo.rdc.aliyun.com/repository/73702-snapshot-ZfDKB4/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

3、mirrors里指定的是仓库的代理,通过在mirrorOf里指定要代理的仓库(可以直接指定,也可以用一些匹配符来指定),来代理向远程仓库发起的请求,如果repositories里的仓库id被mirrorOf匹配到了,那么maven向这个仓库发的请求,就被mirrors规则代理到其他URL了

<mirrors>
    <mirror>
        <id>mirror</id>
        <mirrorOf>!rdc-releases,!rdc-snapshots</mirrorOf>
        <name>mirror</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
</mirrors>

4、servers里定的是身份认证信息,因为一般私服都要用户名和密码,不然不安全,所以看一在这里指定用户名和密码,repository里的id匹配到servers里的id从而找到用户名和密码来访问repository

<servers>
    <server>
        <id>rdc-releases</id>
        <username>xxx</username>
        <password>xxxxxxxx</password>
    </server>
    <server>
        <id>rdc-snapshots</id>
        <username>xxx</username>
        <password>xxxxxxxx</password>
    </server>
</servers>

5、激活profile配置 activeProfiles,用来激活配置的profile。

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

注意:局部配置优先于全局配置。 配置优先级从高到低:pom.xml> user settings > global settings

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值