maven多仓库配置(公司服务器与阿里云仓库)


来源于  https://www.cnblogs.com/ruanjianlaowang/p/11182603.html

 

1. 问题描述

公司内网搭建的有maven私有服务器,但是碰到好几次只有gav没有jar的情况或者最新版本更新不及时,所以需要公司服务器和远程仓库(阿里云)相结合来满足项目需求。

2. 解决方案:

maven仓库配置主要两种方式,一种是全局的;一种是配置在项目中,局部的。

2.1 方式一,全局配置

直接更改repo中的setting,目前项目中正在使用(隐藏替换了公司服务器地址)。

直接上代码

<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- <localRepository>E:\Develop\maven_repo</localRepository> --> <localRepository>E:\m2\repository</localRepository> <servers> <server> <id>releases</id> <username>admin</username> <password>admin@123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin@123</password> </server> </servers> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>central</id> <url>http://dev.hbusy.com/maven/content/repositories/public</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> <repository> <id>cloudera</id> <url>https://repository.cloudera.com/artifactory/clouderarepos/</url> </repository> <!--新增阿里云--> <repository> <id>aliyun</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://dev.hbusy.com/maven/content/repositories/public</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </pluginRepository> <pluginRepository> <id>aliyun</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings> 

配置解析:

Maven 依赖搜索顺序:本地仓库->中央仓库->远程仓库。

1.本地仓库指定

<localRepository>E:\m2\repository</localRepository> 

2. 国内一般直接用远程仓库(阿里云)

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

3. 多仓库配置

  1. 配置多个repository
   <repositories> <repository> <id>aliyun</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </repository> </repositories> 
  1. 在pluginRepository中配置下对应的repository即可
  </pluginRepository> <pluginRepository> <id>aliyun</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </pluginRepository> 

2.2 方式二,项目中局部配置

<project> <repositories> <repository> <id>central</id> <url>http://dev.hbusy.com/maven/content/repositories/public</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> <repository> <id>cloudera</id> <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url> </repository> <!--新增阿里云--> <repository> <id>aliyun</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </repository> </repositories> </project> 

​ 实际开发过程中,一般使用全局配置(在repo中配置setting),除非有些新老项目共存的情况,jar包存在冲突,会单独在项目中配置下。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM