Nexus私服使用笔记:
一.nexus 仓库及配置
1. nexus的仓库类型分为以下四种: group:仓库组, hosted:宿主, proxy:代理, virtual:虚拟
2. 首次登陆默认仓库列表:
PublicRepositories: 仓库组
3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库
Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库
Central: 用来代理maven中央仓库中发布版本构件的仓库
Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库
Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库
Releases: 用来部署管理内部的发布版本构件的宿主类型仓库
Snapshots:用来部署管理内部的快照版本构件的宿主类型仓库
3. 开启远程索引, nexus默认是关闭远程索引下载。
Repositories,找到Apache Snapshots,Codehaus Snapshots和Maven Central,
把每个仓库的configuration下把Download Remote Indexes修改为true,然后右键Repari Index
可切换到“Browse Index”查看索引内容,下载完成后可使用Artifact Search搜索构建名称。
4. 建立宿主仓库
Repositories –> Add –>Hosted Repository
填入Repository ID和Repository Name即可,比如分别填入zfy 和 zfy repostiory,另外把Deployment Policy设置
为Allow Redeploy,点击save就创建完成了。
5. 创建Nexus仓库组
Nexus 中仓库组的概念是Maven没有的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,
我只管根据 groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者
proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。
Public Repositories是一个默认的仓库组,可直接配置使用或新增仓库组
二.maven中使用nexus私服
1. 配置Maven使用Nexus:
修改用户本地settings.xml文件,注意要配置用户名和密码
代码示例:
<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>
</servers>
<mirrors>
<mirror>
<id>nexus-releases</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-snapshots</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<url>http://nexus-snapshots</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-releases</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://nexus-snapshots</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
如果不想使用全局设置(待验证),也可单独在项目中配置仓库地址到私服(用户名和密码server必须在setteing中维护)
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
2. 部署构件至Nexus:
通过nexus直接上传jar 或
配置项目POM.xml,配置distributionManagement:
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
三.nexus 私服权限、角色、用户
避免各个项目上传到同一仓库发生冲突干扰、可以为每个项目创建独立的仓库、每个项目所拥有的仓库只有其项目组成员才能对此仓库进行部署、
修改和删除权限、其他用户只能读取、下载、和搜索该仓库内容。
1、创建项目独立仓库。
(Repositories - Add )
2、为仓库建立权限。
(Privileges - Add - 生成create、read、delete、update、view权限列表)
3、创建包含上述权限的角色。
(Roles - Add - Add Privileges)
4、创建用户、指定用户拥有上面的角色。
(Users - Add - Add Roles)
四.nexus 调度任务(可在Scheduled Tasks配置)
Nexus包含了以下几种类型的调度任务:
Download Indexs:为代理仓库下载远程索引。
Empty Trash:清空Nexus的回收站,一些操作实际是将文件移到了回收站中。
Evict UnusedProxied Items From Repository Caches:删除代理仓库中长期未被使用的构件缓存。
Expire RepositoryCache:Nexus为代理仓库维护了远程仓库的信息以避免不必要的网络流量,该任务清空这些信息以强制Nexus去重新获取远程仓库的信息。
Publish Indexs:将仓库索引发布成可供m2eclipse和其他Nexus使用的格式。
Purge NexusTimeline:删除Nexus的时间线文件,该文件用于建立系统的RSS源。
Rebuild MavenMetadata Files:基于仓库内容重新创建仓库元数据文件maven-metadata.xml,同时重新创建每个文件的校验和md5与sha1。
ReIndexRepositories:为仓库编纂索引。
Remove SnapshotsFrom Repositories:以可配置的方式删除仓库的快照构件。
Synchronize ShadowRepository:同步虚拟仓库的内容(服务基于Maven1)。
一.nexus 仓库及配置
1. nexus的仓库类型分为以下四种: group:仓库组, hosted:宿主, proxy:代理, virtual:虚拟
2. 首次登陆默认仓库列表:
PublicRepositories: 仓库组
3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库
Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库
Central: 用来代理maven中央仓库中发布版本构件的仓库
Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库
Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库
Releases: 用来部署管理内部的发布版本构件的宿主类型仓库
Snapshots:用来部署管理内部的快照版本构件的宿主类型仓库
3. 开启远程索引, nexus默认是关闭远程索引下载。
Repositories,找到Apache Snapshots,Codehaus Snapshots和Maven Central,
把每个仓库的configuration下把Download Remote Indexes修改为true,然后右键Repari Index
可切换到“Browse Index”查看索引内容,下载完成后可使用Artifact Search搜索构建名称。
4. 建立宿主仓库
Repositories –> Add –>Hosted Repository
填入Repository ID和Repository Name即可,比如分别填入zfy 和 zfy repostiory,另外把Deployment Policy设置
为Allow Redeploy,点击save就创建完成了。
5. 创建Nexus仓库组
Nexus 中仓库组的概念是Maven没有的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,
我只管根据 groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者
proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。
Public Repositories是一个默认的仓库组,可直接配置使用或新增仓库组
二.maven中使用nexus私服
1. 配置Maven使用Nexus:
修改用户本地settings.xml文件,注意要配置用户名和密码
代码示例:
<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>
</servers>
<mirrors>
<mirror>
<id>nexus-releases</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-snapshots</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<url>http://nexus-snapshots</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-releases</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://nexus-snapshots</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
如果不想使用全局设置(待验证),也可单独在项目中配置仓库地址到私服(用户名和密码server必须在setteing中维护)
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
2. 部署构件至Nexus:
通过nexus直接上传jar 或
配置项目POM.xml,配置distributionManagement:
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
三.nexus 私服权限、角色、用户
避免各个项目上传到同一仓库发生冲突干扰、可以为每个项目创建独立的仓库、每个项目所拥有的仓库只有其项目组成员才能对此仓库进行部署、
修改和删除权限、其他用户只能读取、下载、和搜索该仓库内容。
1、创建项目独立仓库。
(Repositories - Add )
2、为仓库建立权限。
(Privileges - Add - 生成create、read、delete、update、view权限列表)
3、创建包含上述权限的角色。
(Roles - Add - Add Privileges)
4、创建用户、指定用户拥有上面的角色。
(Users - Add - Add Roles)
四.nexus 调度任务(可在Scheduled Tasks配置)
Nexus包含了以下几种类型的调度任务:
Download Indexs:为代理仓库下载远程索引。
Empty Trash:清空Nexus的回收站,一些操作实际是将文件移到了回收站中。
Evict UnusedProxied Items From Repository Caches:删除代理仓库中长期未被使用的构件缓存。
Expire RepositoryCache:Nexus为代理仓库维护了远程仓库的信息以避免不必要的网络流量,该任务清空这些信息以强制Nexus去重新获取远程仓库的信息。
Publish Indexs:将仓库索引发布成可供m2eclipse和其他Nexus使用的格式。
Purge NexusTimeline:删除Nexus的时间线文件,该文件用于建立系统的RSS源。
Rebuild MavenMetadata Files:基于仓库内容重新创建仓库元数据文件maven-metadata.xml,同时重新创建每个文件的校验和md5与sha1。
ReIndexRepositories:为仓库编纂索引。
Remove SnapshotsFrom Repositories:以可配置的方式删除仓库的快照构件。
Synchronize ShadowRepository:同步虚拟仓库的内容(服务基于Maven1)。