作者:lijunlin66_8460dd | 来源:互联网 | 2023-06-08 15:24
篇首语:本文由编程笔记#小编为大家整理,主要介绍了maven入门基础:配置maven从nexus下载构件(十四)相关的知识,希望对你有一定的参考价值。 一. 单个pom.xml形式:适合单个项目
篇首语:本文由编程笔记#小编为大家整理,主要介绍了maven入门基础:配置maven从nexus下载构件(十四)相关的知识,希望对你有一定的参考价值。
一. 单个pom.xml形式:适合单个项目
<repositories>
<repository>
<id>nexusid>
<name>Nexusname>
<url>http://192.168.0.105:8086/nexus/content/groups/public/url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>nexusid>
<name>Nexusname>
<url>http://192.168.0.105:8086/nexus/content/groups/public/url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
pluginRepository>
pluginRepositories>
注意:setting.xml中不能不能写成这样*,否则所有的构件都会从阿里云上下载,我们的pom.xml配置的私服就无效了。可以写成central,只有中央仓库的构件从阿里云上下载,其他从私服上下载
<mirrors>
<id>alimavenid>
<name>aliyun mavenname>
<url>http://maven.aliyun.com/nexus/content/groups/public/url>
<mirrorOf>centralmirrorOf>
mirrors>
可以看到,maven正在从私服上下载构件
完成后查看,本地仓库和私服仓库
二. setting.xml方式:适合所有项目
1. 定义私服仓库
profiles>
<profile>
<repositories>
<repository>
<id>nexusid>
<name>Nexusname>
<url>http://192.168.0.105:8086/nexus/content/groups/public/url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>nexusid>
<name>Nexusname>
<url>http://192.168.0.105:8086/nexus/content/groups/public/url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
pluginRepository>
pluginRepositories>
profile>
profiles>
<activeProfiles>
<activeProfile>nexusactiveProfile>
activeProfiles>
2. 所有请求转向私服
<mirrors>
<mirror>
<id>nexusid>
<name>Nexusname>
<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
如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的