maven入门基础:配置maven从nexus下载构件(十四)

一. 单个pom.xml形式:适合单个项目

<repositories> <repository> <id>nexus</id> <name>Nexus</name> <url>http://192.168.0.105:8086/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Nexus</name> <!-- 这个地址是私服groups类型的地址,该地址从私服仓库列表的最后一列可查看 --> <url>http://192.168.0.105:8086/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories>

 

 

注意:setting.xml中不能不能写成这样<mirrorOf>*</mirrorOf>,否则所有的构件都会从阿里云上下载,我们的pom.xml配置的私服就无效了。可以写成<mirrorOf>central</mirrorOf>,只有中央仓库的构件从阿里云上下载,其他从私服上下载

<mirrors> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirrors>

可以看到,maven正在从私服上下载构件

完成后查看,本地仓库和私服仓库

 

 

 

 

 

二. setting.xml方式:适合所有项目

1. 定义私服仓库

<!-- 定义私服仓库 --> </profiles> <profile> <repositories> <repository> <id>nexus</id> <name>Nexus</name> <url>http://192.168.0.105:8086/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Nexus</name> <url>http://192.168.0.105:8086/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <!-- 激活私服 --> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>

2. 所有请求转向私服

<mirrors> <mirror> <id>nexus</id> <name>Nexus</name> <!-- http://maven.aliyun.com/nexus/content/groups/public/ --> <url>http://192.168.0.105:8086/nexus/content/groups/public/</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors>

 

 

 

对应私服服务器下的/nexus/storage/目录

三. 配置优先级

settings.xml文件一般存在于两个位置:

  • 全局配置: ${M2_HOME}/conf/settings.xml
  • 用户配置: user.home/.m2/settings.xml
  • (note:用户配置优先于全局配置。)

需要注意的是:局部配置优先于全局配置
配置优先级从高到低:pom.xml> user settings > global settings
如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的

 


__EOF__

本文作者cnhkzyy
本文链接https://www.cnblogs.com/my_captain/p/12245511.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   cnhkzyy  阅读(419)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示