此篇文章主要用于备份 maven 配置,以下配置文件可直接复制后修改 Maven 的仓库地址即可,可以解决部份包无法获取的问题。
步骤
推荐阅读:Maven远程仓库优先级
找到 Maven 的配置文件settings.xml
,将其替换为以下文件,修改本地仓库地址。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 <?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 > D:\maven_repository</localRepository > <pluginGroups > </pluginGroups > <proxies > </proxies > <servers > </servers > <mirrors > </mirrors > <profiles > <profile > <id > aliyun</id > <repositories > <repository > <id > aliyun</id > <url > http://maven.aliyun.com/nexus/content/groups/public</url > <releases > <enabled > true</enabled > </releases > <snapshots > <enabled > true</enabled > <updatePolicy > always</updatePolicy > </snapshots > </repository > </repositories > </profile > <profile > <id > pentaho</id > <repositories > <repository > <id > pentaho</id > <url > https://nexus.pentaho.org/content/repositories/omni/</url > <releases > <enabled > true</enabled > </releases > <snapshots > <enabled > true</enabled > <updatePolicy > always</updatePolicy > </snapshots > </repository > </repositories > </profile > <profile > <id > repo1</id > <repositories > <repository > <id > repo1</id > <url > https://repo1.maven.org/maven2</url > <releases > <enabled > true</enabled > </releases > <snapshots > <enabled > true</enabled > <updatePolicy > always</updatePolicy > </snapshots > </repository > </repositories > </profile > <profile > <id > repo2</id > <repositories > <repository > <id > repo2</id > <url > https://repo2.maven.org/maven2</url > <releases > <enabled > true</enabled > </releases > <snapshots > <enabled > true</enabled > <updatePolicy > always</updatePolicy > </snapshots > </repository > </repositories > </profile > </profiles > <activeProfiles > <activeProfile > aliyun</activeProfile > <activeProfile > repo1</activeProfile > <activeProfile > repo2</activeProfile > <activeProfile > pentaho</activeProfile > </activeProfiles > </settings >
解释一下:包的下载会按照「activeProfiles」中定义的仓库激活顺序来下载,如果第一个找不到就会去找下一个,完美。
来源:https://blog.csdn.net/chrisy521/article/details/121982044
常见问题
Idea 设置了自动导包,但是添加依赖后没有反应;
解决:手动刷新一下 Maven 工程
本地仓库中明明下载了相关依赖,但是 pom.xml 文件中还是爆红;
在 idea 中使用 maven,本地有依赖,但是 Maven 总是去远程仓库找依赖;
解决:idea 中配置 maven vm参数-DarchetypeCatalog=internal