@
maven仓库问题
- 问题描述
- Settings.xml设置
问题描述
在创建新项目时,意外出现了jar包错误
经查询,是因为jar包有错,删除本地依赖重新加载即可。
然而这里我很困惑,我使用的是阿里云仓库,难道是仓库里的jar包有问题吗?于是我使用了控制变量法,想找出出错的是哪个仓库,但是一次次的结果让我更加困惑了。
Settings.xml设置
我将apache-maven-3.8.1/conf/settings.xml调整为这样:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
<localRepository>F:/MavenRepository</localRepository>
<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>aLiCentral</id>
<repositories>
<repository>
<id>aLiCentral</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>spring</id>
<url>https://maven.aliyun.com/repository/spring</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>spring-plugin</id>
<url>https://maven.aliyun.com/repository/spring-plugin</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>jdk-1.8</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>
</profiles>
<activeProfiles>
<activeProfile>aLiCentral</activeProfile>
</activeProfiles>
</settings>
然后将本地仓库里的fasterxml文件夹删掉,重新下载。
设置了public作为镜像,central、spring和spring-plugin作为额外的仓库。按照我所了解到的内容,本地没有的依赖应按先后次序从repository设置的仓库中寻找,如果没有的话再走镜像。我的第一个repository和mirror一样,都是public,但是依然会报错。然后我又进行了以下尝试:
尝试1:将mirror的<mirrorOf>改成<mirrorOf>*</mirrorOf>
- 预期:所有依赖都从镜像下载
- 实际:不报错
尝试2:将profile全部注释掉,只保留mirror,并且<mirrorOf>central</mirrorOf>
- 预期:依赖从被代理的镜像下载
- 实际:报错
尝试3:把mirror也注释掉
- 预期:依赖从官方仓库下载
- 实际:报错
经过以上测试,我更加糊涂了。尝试1可知阿里云的public仓库是正常的,尝试2按理说也应该走public仓库,但是却报错了,尝试3按理说是从官方仓库下载的,难道官方仓库里的jar包有问题?。。历时两天问题依然没有解决。