1. 下载nexus
下载地址: https://www.sonatype.com/download-oss-sonatype
2. 启动对应版本的nexus
…/nexus-2.14.8-01-bundle\nexus-2.14.8-01\bin\jsw
3. 访问nexus
http://localhost:8081/nexus
默认用户名/密码 : admin/admin123
type表示仓库类型:
类型 | 用途 |
---|---|
hosted | 表示当前开发人员上传的,包括snapshots快照版本/releases稳定版本/3rd party第三方包三种仓库;表示当前开发人员上传的,包括snapshots快照版本/releases稳定版本/3rd party第三方包三种仓库; |
proxy | 表示中央服仓库,包括snapshots快照版本/releases稳定版本两种仓库; |
举个例子就是,
你上传jar包时,release版本就会上保存到hosted的releases仓库,snapshot版本就会保存到hosted的snapshots仓库;
你下载jar包时,就回到中央仓库找;
4. 初始化nexus
刚启动的nexus是搜不到jar包信息的,需要从中央仓库同步先
选中central仓库—>tab页中选中configuration---->download remote indexs 选择true
选择完后,nexus会创建一个任务从中央仓库同步jar包索引,耗时一两个小时;
5. 上传jar包
a)maven的settings.xml中配置nexus的认证信息
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
b)项目的pom.xml中配置nexus的地址信息,此处id必须和settings中的id对应
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>nexus releases repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>nexus snapshotRepository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
c) deploy jar包
6. 下载jar包
maven的settings.xml文件中配置
content/groups/public仓库表示同时可以从proxy/hosted仓库获取jar包
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>public</id>
<name>public repository</name>
<url>http://ip:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>