项目中单独指定maven远程仓库

本文详细指导如何在Maven项目中通过添加repositories和pluginRepositories节点,指定远程阿里云仓库地址,解决插件依赖问题。包括配置示例和解决常见问题的方法。

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

如果我们要在项目中单独指定远程仓库得地址的话

1.pom.xml添加配置

添加repositories节点

<repositories>
        <repository>
            <id>aliyun</id>
            <url>https://maven.aliyun.com/repository/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

其中< release>标签和snapshot标签表示是否从远程仓库引入release或者snapshot版本

 配置之后 :  问题maven依赖的插件 没有使用阿里云仓库的地址

        1.发现maven的插件库还是用的是默认的仓库地址

        2.项目的依赖是使用的阿里云仓库地址

添加pluginRepositories节点

maven命令需要的插件(比如clean、install都是maven的插件),走的还是默认的repository。

查看maven的官方文档(http://maven.apache.org/pom.h... ),可以看到pom中除了repositories节点之外,还有一个关于仓库的节点是pluginRepositories:

Repositories are home to two major types of artifacts. The first are artifacts that are used as dependencies of other artifacts. These are the majority of plugins that reside within central. The other type of artifact is plugins. Maven plugins are themselves a special type of artifact. Because of this, plugin repositories may be separated from other repositories (although, I have yet to hear a convincing argument for doing so). In any case, the structure of the pluginRepositories element block is similar to the repositories element. The pluginRepository elements each specify a remote location of where Maven can find new plugins.

所以我们还需要再pom中增加pluginRepositories才可以。

完整的pom文件如下:

<repositories>
    <repository>
        <id>aliyun</id>
        <url>https://maven.aliyun.com/repository/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>aliyun-plugin</id>
        <url>https://maven.aliyun.com/repository/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

 再次运行: 都走了阿里云的仓库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值