1.搭建maven的私服
http://www.sonatype.org/nexus/downloads/
搭建私服是团队开发的基础,才能实现组内或者组间的依赖共享,要搭建私服使用工具nexus
搭建私服启动登陆之后,发现仓库类型可以分为三大类:
hosted:表示主机,也就是当前这台服务器可以直接访问和操作的仓库,但是其他机器可以通过配置用户的方式来访问和修改
release:表示释放版,也就是如果你的jar包版本是release版本,将上传到该仓库中
snapshot:保存对应的快照版本的jar包
3th party:表示第三方的仓库
group:表示一个群组,方便进行仓库的统一管理
私服搭建好之后,需要在我们的开发环境中使用
在eclipse层面进行使用
<!-- 配置远程仓库,指的是我们下载依赖时,可以从该私服来进行下载 -->
<repositories>
<repository>
<id>nexus</id>
<name>TeamNexus Repository</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
配置上传的远程仓库的URL
<distributionManagement>
<!-- 释放版的url配置 -->
<repository>
<id>repository-release</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<!-- 快照版的url配置 -->
<snapshotRepository>
<id>repository-snapshot</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
配置认证账户,在maven的setting配置文件
<server>
<id>repository-release</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>repository-snapshot</id>
<username>deployment</username>
<password>deployment123</password>
</server>
在maven层面进行使用,使用更为方便
在setting配置文件中添加关于私服的配置
<!-- 配置私服仓库 -->
<profile>
<id>my-nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://localhost:8081/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://localhost:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
需要激活配置
<activeProfiles>
<activeProfile>jdk-1.8</activeProfile>
<activeProfile>my-nexus</activeProfile>
</activeProfiles>
如果需要上传jar包给私服
<distributionManagement>
<!-- 释放版的url配置 -->
<repository>
<id>repository-release</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<!-- 快照版的url配置 -->
<snapshotRepository>
<id>repository-snapshot</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
2.维护私服索引
首先需要下载私服的索引文件:http://repo1.maven.org/maven2/.index/,下载nexus-maven-repository-index.gz和nexus-maven-repository-index.properties
索引文件采用特殊的压缩方式,不能使用解压缩软件来解压,需要特别下载一个解压缩工具:indexer-cli-5.1.0.jar
解压缩:java -jar indexer-cli-5.1.0.jar -u nexus-maven-repository-index.gz -d indexer
解压完成之后,就需要配置索引文件
(1)停止nexus服务器
(2)覆盖索引文件,将私服的indexer下的中央仓库的索引全部删除,将解压出来的文件覆盖进去
(3)重启nexus的服务器,索引更新完成