pom中配置maven仓库(阿里仓库)

pom中配置maven仓库
配置maven仓库,可以在maven的settings.xml里改。优点是全局统一配置,缺点是不受你项目git管理。
也可以直接在pom.xml里改, 好处就是 可以受git管理,缺点是每个项目的pom你都得配置。

maven自动下载依赖时,会涉级读取三个配置文件,分别是项目下的pom.xml 文件 、家目录下的.m2/settings.xml 与 maven 全局配置settings.xml ,后面两者不难理解,就像linux下的用户一样,有一个/etc/profile ,用户用目录下还有一个.bash_profile 文件是一样的,用户自定义配置会覆盖全局配置。

三者的级先是 pom.xml > /home_dir/.m2/settings.xml > /maven_dir/conf/settings.xml 。

总结: 相对来说,在pom中配置maven仓库比较好,项目代码放到哪都没有问题。

<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>

注意: pluginRepositories配置容易被忽略,pluginRepositories用来配置maven插件的远程仓库,注意如上也需要配置。否则只有项目本身的依赖,走了aliyun这个repository,maven命令需要的插件(比如clean、install都是maven的插件),走的还是默认的repository。

原文链接:https://blog.csdn.net/inthat/article/details/105195484

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
配置阿里云私服仓库,你可以按照以下步骤进行操作: 1. 首先,你需要搭建阿里maven私服仓库。你可以使用阿里云提供的Maven仓库服务,或者自己搭建一个私服仓库。 2. 如果你选择使用阿里云的Maven仓库服务,你需要将以下URL添加到你的Maven配置文件的<mirrors>标签: <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url> </mirror> 这个配置将指定所有的仓库镜像使用阿里云的公共仓库。 3. 接下来,你可以手动上传本地的jar包到阿里maven私服仓库。你可以使用以下命令将jar包上传到私服仓库: mvn deploy:deploy-file -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version> -Dpackaging=<packaging> -Dfile=<file> -Durl=<url> -DrepositoryId=<repositoryId> 其,<groupId>是jar包的groupId,<artifactId>是jar包的artifactId,<version>是jar包的版本号,<packaging>是jar包的打包类型,<file>是要上传的jar包文件的路径,<url>是私服仓库的URL,<repositoryId>是私服仓库的ID。 4. 另外,你也可以通过使用IDEA自动上传本地项目到阿里maven私服仓库。在IDEA,你可以在项目的Maven设置配置私服仓库的URL和凭据,然后使用Maven的deploy命令将项目上传到私服仓库。你可以在IDEA的Maven工具窗口找到deploy命令。 5. 最后,要从阿里云私服仓库拉取maven依赖的jar包,你需要在项目的pom.xml文件配置阿里云私服仓库的镜像URL。你可以添加以下代码到<pom>标签: <repositories> <repository> <id>aliyunmaven</id> <url>https://maven.aliyun.com/repository/public</url> </repository> </repositories> 这将使Maven阿里云私服仓库拉取jar包。 请注意,阿里maven私服仓库有多个仓库,你需要根据你引入的jar包在阿里仓库的归属来决定是否需要添加新的仓库。你可以查看阿里maven仓库的文档了解更多详情。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值