maven的配置文件优先级: pom.xml> user settings > global settings ;
通过maven的配置文件优先级和IDEA的settings(设置)实现多仓库;
1、前言
公司内部开发项目时一般会有一个公司的Maven私服,这个私服只能在公司内网中使用;如果,我们不再公司的情况下可能需要下载一些其他 jar 包。基于这种情况,我们可以配置两个本地仓库:公司使用({basedir}/.m2/repository/) 和 自己使用({basedir}/.aliyun/repository/)。在切换maven配置文件settings.xml时,一定要清楚优先级关系。
2、配置文件优先级
maven的配置文件优先级: pom.xml> user settings > global settings ;
user settings: user.home/.m2/settings.xml
global settings:${M2_HOME}/conf/settings.xml
用户配置优先于全局配置,存在覆盖配置问题
3、解决方案
3.1 settings.xml文件示例:
1 2 3 4 5 6 7
<!-- localRepository # 本地仓库位置 | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>D:/Users/24458/ideaCaches/.aliyun/repository</localRepository>
<mirrors> <!-- mirror # 镜像 | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <mirror> <id>aliyun-public</id> <mirrorOf>*</mirrorOf> <name>aliyun public</name> <url>https://maven.aliyun.com/repository/public</url> </mirror>