1、修改maven-central仓库
如下图所示将maven-central仓库代理的中央仓库改为阿里的镜像仓库
http://maven.aliyun.com/nexus/content/groups/public
2、手动创建3rd-party仓库
首先点击create repository
选择如下仓库类型
输入如下配置即可
3、配置项目强制走私服
为当前机器配置统一的仓库地址,一般是直接配置为私服组(maven-public),私服组会去找对应的仓库,此时需要在settings.xml加入如下配置
</profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<name>Nexus </name>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Nexus Plugin Repository</name>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
激活对应的profile,在项目执行构建的时候,就会将profile中的仓库配置应用到每个项目中去。
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
最后还需要通过镜像机制,让所有对远程仓库的请求通过镜像走私服,需要进行如下配置
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
4、验证配置是否成功
在pom文件中加入kafka依赖
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.10</artifactId>
<version>0.10.2.1</version>
</dependency>
应该有的效果是,先找本地仓库,本地仓库没有就从私服去下载,私服再从阿里云去下载,然后私服上会有一份依赖,然后本地仓库里也有一份依赖。
本地仓库的情况
私服情况