解读maven配置阿里云镜像问题
作者:普通网友 时间:2023-02-28 11:57:56
maven配置阿里云镜像
打开maven配置文件,找到标签,添加如下:
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
设置全局的jdk,在配置文件配置如下:
<profile>
<id>jdk18</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
设置局部的jdk,在项目的pom,xml文件中添加如下build元素
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
maven配置阿里云镜像仓库不生效
问题
在{MAVEN_HOME}/conf/settings.xml中添加镜像配置:
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
但是项目更新时仍然会从http://repo.maven.apache.org/maven2下载依赖。
解决方法
在项目的pom.xml中添加如下配置
<repositories>
<repository>
<id>central</id>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://maven.aliyun.com/repository/public</url>
</pluginRepository>
</pluginRepositories>
原因
项目的pom会继承自super pom,在super pom中指定了从仓库的地址:
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
因此需要在项目中覆盖这一配置。
来源:https://blog.csdn.net/qq_46416934/article/details/124313349
标签:maven,配置,阿里云,镜像
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C# XML基础入门小结(XML文件内容增删改查清)
2022-10-18 17:12:02
Java精确抽取网页发布时间
2022-03-24 17:20:11
SpringBoot 整合mybatis+mybatis-plus的详细步骤
2022-09-29 21:06:10
![](https://img.aspxhome.com/file/2023/5/72915_0s.png)
Flutter 分页功能表格控件详细解析
2023-09-22 20:02:45
![](https://img.aspxhome.com/file/2023/2/104692_0s.gif)
Java开发中可以防止界面假死的刷新代码
2023-11-23 22:23:41
spring boot如何指定启动端口
2021-06-27 19:52:14
![](https://img.aspxhome.com/file/2023/0/65370_0s.png)
java计算两点间的距离方法总结
2023-12-21 17:32:45
从 JVM 中深入探究 Synchronized作用及原理
2023-07-28 17:22:33
Java简单实现定时器
2023-07-16 18:10:58
![](https://img.aspxhome.com/file/2023/6/76536_0s.jpg)
SpringBoot整合Elasticsearch7.2.0的实现方法
2023-11-09 19:22:56
![](https://img.aspxhome.com/file/2023/6/113406_0s.png)
Java计算文本MD5加密值的方法示例
2023-11-15 13:18:48
SpringBoot中使用Servlet三大组件的方法(Servlet、Filter、Listener)
2021-07-19 18:41:43
![](https://img.aspxhome.com/file/2023/3/104703_0s.png)
Maven构建时跳过部分测试的实例
2022-08-30 03:42:50
关于Future机制原理及解析
2022-01-23 03:57:48
Java BigDecimal案例详解
2021-09-15 12:03:43
![](https://img.aspxhome.com/file/2023/9/63509_0s.png)
c#高效的线程安全队列ConcurrentQueue<T>的实现
2021-07-27 11:01:05
![](https://img.aspxhome.com/file/2023/6/81126_0s.png)
SpringMVC教程之文件上传与下载详解
2022-12-21 03:49:09
Java数据结构之栈与队列实例详解
2021-05-29 03:25:13
![](https://img.aspxhome.com/file/2023/1/61591_0s.png)
Java 实现分布式服务的调用链跟踪
2023-11-25 10:24:55
![](https://img.aspxhome.com/file/2023/4/60124_0s.png)
Android Studio 通过登录功能介绍SQLite数据库的使用流程
2023-09-22 00:37:29