Maven配置私有仓库

前言

  当公司或个人具有自己独有的jar时,不想公开,一般就会放在自己的私有Maven仓库中,在项目中需要引用,此时就需要将公司私有仓库配置到maven当中,一般我们的maven配置的都是aliyun的maven公有仓库,但此时我们不但要配置私有仓库还要配置公有仓库,因为有的公有jar,私有仓库中不一定有,所以此时就涉及到maven多仓库配置喽。

maven配置一共分为两种

  1. 统一配置,通过maven的setting.xml文件配置,每个项目都可直接使用。
  2. 项目配置,在项目的pom.xml文件中配置(有得项目需要进行定制化配置,但其他项目又不需要这个仓库)

以下使用的统一配置方式来进行配置哈。项目配置可自行百度。希望可以帮助到大家。

1、Setting.xml

在本地maven的setting.xml配置文件中进行私有仓库配置。

在<servers></servers>标签中配置仓库访问账号和密码。

在<mirrors></mirrors>标签中配置仓库地址。

在<profiles></profiles>标签中配置多仓库使用。

在<activeProfiles></activeProfiles>中激活仓库,否则配置无效。

<mirrors>
<mirror>
<id>nexus-repository</id>
<mirrorOf>central</mirrorOf>
<name>Nexus repository</name>
<url>http://192.168.0.1::8081/content/groups/public/</url>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>\
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>repository</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>alimaven</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>Dcm4Che</id>
<name>Dcm4Che</name>
<url>http://www.dcm4che.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>repository</activeProfile>
<activeProfile>alimaven</activeProfile>
</activeProfiles>

2、刷新IDEA项目

查看maven仓库引用 

 

此刻配置就成功了,即可使用远程私有仓库拉去jar,如果找不到相关jar,会自动去aliyun中央仓库下载公有maven坐标。 

 

posted @   阿尔法哲  阅读(13391)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示