前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >maven配置

maven配置

原创
作者头像
悠悠我心
修改2020-04-03 10:17:37
1.4K0
修改2020-04-03 10:17:37
举报
文章被收录于专栏:spring 开发spring 开发

​​maven多仓库查找依赖的顺序大致如下:

 (1),在本地仓库中寻找,如果没有则进入下一步。

 (2),在全局配置的私服仓库(settings.xml中配置的并有激活)中寻找,如果没有则进入下一步。

 (3),在项目自身配置的私服仓库(pom.xml)中寻找,如果没有则进入下一步。

 (4),在中央仓库中寻找,如果没有则终止寻找

默认中央仓库的地址:

https://repo1.maven.org/maven2/

在中国访问仓库比较慢,一般替换为阿里云的中央仓库

第一种 统一修改仓库地址

可以直接修改Maven conf文件夹中的setting.xml文件

setting.xml里面有个mirrors节点,用来配置镜像URL。mirrors可以配置多个mirror,每个mirror有id,name,url,mirrorOf属性。

  • id是唯一标识一个mirror
  • name貌似没多大用,相当于描述
  • url是官方的库地址
  • mirrorOf代表了一个镜像的替代位置,例如central就表示代替官方的中央库。

mirror也不是按settings.xml中写的那样的顺序来查询的。所谓的第一个并不一定是最上面的那个。

当有id为B,A,C的顺序的mirror在mirrors节点中,maven会根据字母排序来指定第一个,所以不管怎么排列,一定会找到A这个mirror来进行查找,当A无法连接,出现意外的情况下,才会去B查询。

<mirrors>

   <mirror>

      <id>nexus-ali</id>

      <mirrorOf>central</mirrorOf>

      <name>Nexus aliyun</name>

      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

  </mirror>

</mirrors>

第二种 分别给每个项目配置不同的中央库

<repositories>

<repository>

     <id>nexus-ali</id>

      <name>Nexus aliyun</name>

      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

 </repository>

</repositories>

第三种 如果有私服,从后台设置私服仓库的远程地址为阿里云的镜像地址

(1)在私服的后台设置仓库的镜像地址(用于私服不存在时候从该地址下载)

(2)修改maven的settings.xml的配置文件:配置下载地址 在<profiles>里配置,同时激活两个,可以从两个地址下载

<profile>

<id>nexus</id>

<repositories>

<repository>

<id>nexus</id>

<name>Nexus Repository</name>

<url>http://10.110.16.44:8081/nexus/content/groups/public/</url>

<releases>

<enabled>true</enabled>

</releases>

<snapshots>

<enabled>true</enabled>

</snapshots>

</repository>

</repositories>

<pluginRepositories>

<pluginRepository>

<id>nexus</id>

<name>Nexus pluginRepository</name>

<url>http://10.110.16.44:8081/nexus/content/groups/public/</url>

<releases>

<enabled>true</enabled>

</releases>

<snapshots>

<enabled>true</enabled>

</snapshots>

</pluginRepository>

</pluginRepositories>

</profile>

<profile>

<id>nexus-ali</id>

<repositories>

<repository>

<id>nexus-ali</id>

<name>ali mirror central</name>

<url>http://maven.aliyun.com/nexus/content/groups/public/</url>

<snapshots>

<enabled>true</enabled>

</snapshots>

<releases>

<enabled>true</enabled>

</releases>

</repository>

</repositories>

<pluginRepositories>

<pluginRepository>

<id>nexus-ali</id>

<url>http://maven.aliyun.com/nexus/content/groups/public/</url>

<snapshots>

<enabled>true</enabled>

</snapshots>

<releases>

<enabled>true</enabled>

</releases>

</pluginRepository>

</pluginRepositories>

</profile>

<activeProfiles>

<activeProfile>nexus</activeProfile>

<activeProfile>nexus-ali</activeProfile>

</activeProfiles>

项目如何上传到私服仓库(快照和正式版)

1.在 pom 文件中添加如下代码

<distributionManagement>

     <repository>

         <id>releases</id>

          <name>Releases</name>

          <url>http://10.110.16.44:8081/nexus/content/repositories/releases/</url>

     </repository>

     <snapshotRepository>

         <id>snapshots</id>

         <name>Snapshot</name>

         <url>http://10.110.16.44:8081/nexus/content/repositories/snapshots/</url>

     </snapshotRepository>

</distributionManagement>

2.setting文件里设置

    <servers>

        <server>

           <id>releases</id>  对应pom 文件的id

            <username>admin</username> 私服用户名

            <password>admin111</password> 私服密码

        </server>

        <server>

             <id>snapshots</id>

             <username>admin</username>

             <password>admin111</password>

         </server>

     </servers>

注意:如果是快照版本,那么在mvn deploy时会自动发布到快照版本库中,会覆盖老的快照版本,而在使用快照版本的模块,在不更改版本号的情况下,直接编译打包时,maven会自动从镜像服务器上下载最新的快照版本。如果是正式发布版本,那么在mvn deploy时会自动发布到正式版本库中,而使用正式版本的模块,在不更改版本号的情况下,编译打包时如果本地已经存在该版本的模块则不会主动去镜像服务器上下载

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ​​maven多仓库查找依赖的顺序大致如下:
  • 第一种 统一修改仓库地址
  • 第二种 分别给每个项目配置不同的中央库
  • 第三种 如果有私服,从后台设置私服仓库的远程地址为阿里云的镜像地址
  • 项目如何上传到私服仓库(快照和正式版)
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档