1. 发生背景
物联网开发计划结束,另一个项目那边有需求,于是让我们转个项目进行开发。然后在搭建新项目的时候,突然发现这个项目里面用到了自己私库的jar包,并且这些jar包在公库里找不到。
关键问题来了,就是配置多个仓库!
2. 失败的解决方法
我原本以为这个不就是在maven配置的时候加一个镜像就能解决的事情,结果并不是!
最初的样子如下:
后面加了一个私库的镜像后,如下:
- 结果只有没有找到私有的镜像中的包。后面去查资料才发现,配置多个
mirror
时,只有第一个才会生效。跟我想象的根本不一样。
3. 成功的解决方法
解决方法:设置全局多仓库。。
配置格式如下:
<profiles>
<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>
<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>Releases</id>
<repositories>
<repository>
<id>Releases</id>
<url>http://XX.XX.XX.XX:8081/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
配置完profile
后还要配置activeProfiles
,其配置如下:
<activeProfiles>
<activeProfile>Releases</activeProfile>
<activeProfile>aliyun</activeProfile>
</activeProfiles>
配置完之后,便可以重两个仓库中拉取jar包,如果一个仓库中不存在,便会从另一个仓库中去拉取jar包。