>> 安装Nexus:
直接下载bundle版本,然后将其安装成服务后自启动。访问:http://localhost:8081/nexus/ 即可
>> Nexus仓库分类的概念:
maven可以直接从宿主仓库(hosted)下载构件;也可以从代理仓库(proxy)下载构件,而代理仓库会间接从远程仓库下载并缓存构件;最后,为了方便,Maven可以从仓库组(group)下载构件,而仓库组没有实际内容,它会转向其包含的宿主仓库或者代理仓库获得实际构件的内容。
>> Nexus搜索功能:
除了提供简单的key关键词搜索外,在搜索页面左上角的下拉菜单选择高级搜索功能:
* GAV搜索 GAV Search:运行用户通过设置groupId、artifactId、version等信息来搜索
* 类名搜索 Classname Search:允许用户搜索包含某个java类的构件
* 校验和搜索 Checksum Search:运行用户直接使用构件的校验和来搜索该构件
除了下载使用远程仓库的索引,我们也能为hosted仓库和proxy仓库建立索引。只需要在仓库上右击,从弹出菜单中选择ReIndex即可,待索引编纂任务完成,我们就能够搜索该仓库所包含的构件了。
>> 配置Maven从Nexus下载构件:
对于所有项目而言,最好在settings.xml文件中统一设置:
<settings> ... <profiles> <profile> <id>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> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
如果你只想要从nexus私服中下载,没有的也不从中央仓库下载,可以配置一个mirror:
<settings> ... <mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/nexus/content/groups/public</url> </mirror> </mirrors> <profiles> <profile> <id>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> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
Nexus仓库对于匿名用户是只读的,为了能够部署构件,还需要在settings.xml文件中配置认证信息:
<servers> <server> <id>nexus-releases</id> <username>xiongneng</username> <password>xiongneng</password> </server> <server> <id>nexus-snapshots</id> <username>xiongneng</username> <password>xiongneng</password> </server> </servers>
注意:这里面的两个id值会被下面的project里面的distributionManagement里面的repository里面的id用到。
>> 部署构件至Nexus:
* 使用maven自动部署构件到Nexus中,推荐这种方法:
<project> ... <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 Snapshots Repository</name> <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement> ... </project>
>> Nexus权限管理:
Nexus预定义的一些常用且重要的角色包括:
* UI:Basic UI Privileges:包含了访问Nexus界面必须的最基本权限
* UI:Repository Browser:包含了浏览仓库页面所需要的权限
* UI:Search:包含了访问快速搜索栏以及搜索页面所需要的权限
* Repo:All Repositories(Read):给予用户读取所有的仓库内容的权限,没有仓库的读权限,用户将无法在仓库页面上看到实际的仓库内容,也无法使用maven从仓库下载构件
Repo:All Repositories(Full Control):给予用户完全控制所有的仓库内容的权限。用户不仅可以浏览、下载构件,还能部署构件以及删除仓库内容。默认情况下nexus包含一个匿名用户角色,所有未登陆用户默认就是这个角色,它拥有除了All Repositories(Full Control)外的所有角色包含的所有权限。
>> 为项目分配独立的仓库:
先为Releases、Snapshots两个仓库建立权限,选择Repository Target Privilege类型,然后创建一个包含上述权限的角色。角色建立完后,根据需要将此角色分配给项目的成员,那么这个项目的成员就可以部署构件到里面了,而其他的项目成员只能查看和下载。
本人博客已搬家,新地址为:http://yidao620c.github.io/