一、 本地仓库
二、 中心仓库
三、 私有仓库
Maven仓库示意图
私有仓库是局域网内部的仓库,其安装是使用nexus安装:
1、 Nexus的安装:
1、 下载并且解压缩。
2、 将bin添加到环境变量。
3、 Nexus install将nexus安装到windows的服务中。
如果出现这种情况,使用管理员身份进入控制台。
这时候去服务管理中查看服务是否已注册好。
4、修改nexus/jsw/conf中的wraper.conf文件中的内容,将#Set the JVM executable中的java路径,jdk/bin/java。
5、 nexus start启动服务。
6、 通过访问localhost:8081/nexus访问。
7、登录(log in)
用户名:admin
密码:admin123
2、 仓库讲解
1、 hosted仓库:内部的发布仓库。
2、 proxy的仓库:从远程仓库中寻找数据的仓库。
3、 group仓库:组仓库用来方便开发人员进行设置的仓库。
3、 私有仓库的设置
1、 更新私有仓库的索引
或者直接下载索引,将其拷贝到中央仓库的索引存储中。文件路径:
F:\nexus-2.14.3-02-bundle\sonatype-work\nexus\indexer\central-ctx
2、 设置镜像(本地仓库中的setting.xml)
<mirror>
<id>central</id>
<!--或者用逗号隔开-->
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://192.168.1.102:8081/nexus/content/groups/public/</url>
</mirror>
所有仓库都从这里找。
3、 在setting.xml中配置仓库,此时本机中的所有maven项目都会去私有仓库中查询依赖。
在profiles下修改配置:
<profile>
<id>central-repos</id>
<repositories>
<repository>
<id>central</id>
<name>Central</name>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots>
<enabled>true</enabled>
<snapshots>
</repository>
</repositories>
</profile>
激活profile:
4、 项目的发布
1、 设定release工厂和SNAPSHOT快照工厂。发布指令:mvn clean deploy
在父类中的pom.xml中配置,配置如下:
<distributionManagement>
<snapshotRepository>
<id>hello-snapshots</id>
<name>Hello ProjectSNAPSHOTS</name>
<url>http://192.168.1.102:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>hello-releases</id>
<name>Hello ProjectRelease</name>
<url>http://192.168.1.102:8081/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
2、 设置访问权限
系统提供的几种用户:
在setting.xml中配置:
Servers下修改配置:
<server>
<id>hello-snapshots</id>
<username>development</username>
<password>development123</password>
</server>
<server>
<id>hello-releases</id>
<username>development</username>
<password>development123</password>
</server>
5、 创建项目工厂和设置权限
1、 创建两个工厂,release和snapshot版本。
2、 配置权限。
3、 创建角色,并且分配权限。
4、 创建用户
5、 创建发布的工厂
将parent中发布的配置的地址改成项目工厂的snapshots和releases工厂地址。
且配置setting.xml中的修改用户为你添加的用户。