原文:http://m.blog.csdn.net/article/details?id=49667971html
当咱们的项目开发完成之后,可能要进行发布(若是是独立的项目,就不须要发布啦,若是是模块项目,那么就要发布到nexus里,供其余开发人员下载调用。)maven
要想发布项目到nexus里,必须经过<distributionManagement>标签来进行配置。在以前的文章中有介绍nexus的工厂类别,其中提到两个:hosted里的Releases、Snapshots.ui
当咱们发布项目到nexus里时,若是项目版本是x.x.x-Releases,则会发布到Releases工厂中;而项目版本是x.x.x-SNAPSHOTS则发布到Snapshots工厂中。url
配置<distributionManagement>:.net
代码:code
<distributionManagement> <repository> <id>releasesId</id> <name>Releases name</name> <url>http://localhost:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>snapshots id</id> <name>snapshots name</name> <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
右键项目 --> run as ---> maven Build... --> 输入clean deploy命令(一开始会下载一些依赖包,淡定.....)。server
后面咱们会看到以下的提示信息:xml
怎么来设置受权呢?htm
【1】:去到nexus管理界面 --- > 左侧菜单栏“Security” --> “Users” ,右侧所列出的用户中,只有deployment用户才有发布项目到nexus的权限。blog
【2】:在setting.xml里使用<server>标签进行受权。server里的id对应<distributionManagement>里设置的id。
流程是:当执行clean deploy命令进行发布时,首先会找到<distributionManagement>的配置,获取配置信息。
而后若是setting.xml里有配置server,对比id值,若是匹配的上,就验证server里的用户是否拥有发布的权限,有权限就把项目发布到对应的仓库里。
setting.xml中server标签代码:
<server> <id>releasesId</id> <username>deployment</username> <password>deployment123</password> </server> <server> <id>snapshotsid</id> <username>deployment</username> <password>deployment123</password> </server>
至此,发布的配置就完成了,执行clean deploy命令后,就会在nexus的Releases或Snapshots仓库中找到发布的项目了。
若是咱们不想把全部项目都发布到nexus的Releases或Snapshots仓库中,而是想在nexus里能为每一个项目开辟一个空间,存放每一个项目本身发布上去的依赖包。
要实现这种效果,须要如下几步操做:
(1)在nexus里为每一个项目建立hosted类型的工厂(Releases或Snapshots两种)
(2)在Securiy --> Privileges里添加Releases或Snapshots两种工厂的特权(能够执行那些操做,如往工厂里发布,查看,删除等特权)
(3)在Security --> Roles 里添加角色,为角色配置权限
(4)在Security --> Users 里添加用户,为用户设定角色
(5)在pom.xml里的 <distributionManagement>把url改成对应的工厂路径,在setting里的server里设定对应的用户密码
执行clean deploy命令后: