概览
settings
- 全局设置: $M2_HOME/conf/settings.xml
- 用户设置: ${user.home}/.m2/settings.xml
基本介绍:
M2HOME是你的maven包解压后的目录.
M
2
H
O
M
E
是
你
的
m
a
v
e
n
包
解
压
后
的
目
录
.
{user.home} 在windows中,可以通过资源管理器,在地址栏中输入%HOMEPATH%打开, 如下图所示:
maven在执行时读取设置, 可以只使用全局设置. settings.xml 可以配置localRepository, server, proxy, mirror等等, 根据 best place for repository , 感觉, settings.xml配置本地归档, 还有mirror, 以及保密信息(服务器用户密码)比较合适, 下面是stackoverflow答案的截图:
最佳实践:
拷贝全局设置到用户设置, 修改用户设置, 最终两份设置会融合, 用户设置会覆盖全局设置. 对于repository的使用, 一般公司中最好用仓库管理系统, 方便对多个仓库的管理.
参考用户设置:
<localRepository>D:\repository</localRepository>
<mirrors>
<mirror>
<id>nexus public</id>
<mirrorOf>*</mirrorOf>
<name>nexus public</name>
<url>http://172.16.20.253:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>downloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>downloadSources</activeProfile>
</activeProfiles>
pom
- super pom
maven从3版本以后, 移到lib/maven-model-builder-3.x.x.jar - project pom
继承super pom
配置依赖, 插件, 还有仓库. pom是对单个工程的配置, 而settings可以对所有工程统一配置.
repository
方便对仓库的可视化管理, 常用的仓库管理
- Apache Archiva (open source)
- JFrog Artifactory Open Source (open source)
- JFrog Artifactory Pro (commercial)
- Sonatype Nexus OSS (open source)
- Sonatype Nexus Pro (commercial)
我们使用nexus
nexus仓库的一些概念:
- hosted, 本地仓库, 可以将公司内部开发的jar包上传到这里
- proxy, 代理仓库, 代理远程的公共仓库, 如maven中央仓库或一些第三方公共仓库。
- group, 仓库组, 用来合并多个hosted/proxy仓库, 当你的项目希望在多个repository使用依赖项时, 无需引用多个仓库了, 只需要引用一个类型为group的repository即可.
使用仓库组统一管理, 将hosted, proxy并在一起, 可参考 nexus 仓库管理
group管理如下图所示: